Problem providing feedback with if mouse.isPressedIn()

Hello everyone, I’m new to PsychoPy and I’m designing an experiment where the participants will have limited time to repeat a sentence they saw previously. I would like to give the participants feedback if their repetition is too slow, so in the routine for the repetition, I built a button using a Polygon and a Mouse element and added a Code in the same routine to test if the mouse is pressed. However, it sometimes gives negative feedback even if the mouse is clicked in time. What could be causing this problem? Many thanks in advance!

my code:
End Routine:
repeat_status = ‘’

if exp_wh_mouse.isPressedIn(exp_wh_box):
msg_exp = ‘’
repeat_status = ‘done’
else:
msg_exp = ‘Zu langsam!’
repeat_status = ‘slow’

thisExp.addData(‘repeat_status’, repeat_status)

I also tried if mouse.clicked_name[-1] == ‘exp_wh_box’:, it works fine when the mouse is clicked, but when it is not, the experiment crashes with an index error.