Skip next routine when 1 of 2 buttons is clicked

OS (e.g. Win10): Windows 11
PsychoPy version (e.g. 1.84.x): 2023.2.3

What are you trying to achieve?:
My experiment is a traditional Old/New Recognition Test. In my old/new routine, I have two button components (named ‘button’ for Old and ‘button_2’ for New). If button (old) is selected, participants will move onto the next routine (named source) asking where they have previously seen the image. However, if button_2 (new) is pressed, I want to skip the next routine (source) and continue on with the loop.

What did you try to make it work?:
For this I tried: in the Each Frame of the code component

if button_2.contains(mouse) and mouse.isPressedIn(button_2):
button_2_clicked = True
if button_2.contains(mouse) and mouse.isPressedIn(button):
button_2_clicked = False

I’m not sure if I need to put something into the End Routine of this code component OR
Add a code component to the next routine (source) and in Begin Routine have:
if button_2_clicked:
continueRoutine = False

I’m brand new to PsychoPy and know nothing about python, so I’m in the dark here. I was going back and forth with ChatGPT for a while, but it’s using the 2022 version of psychopy and I was running into errors.

What specifically went wrong when you tried that?:
The source routine is not skipped when button_2 is pressed.