How to you turn off a script if it has an error

for my game i have a pointer that runs on a script to pick witch object to point at. it does this sequentaly and is bound to fail.

How do you tell the script to stop running if it fails?


You could do something like


Hugh ive never used those before can you explain them?

Make the try-block as small as possible. Otherwise the code might result in an undefined state (e.g. halfway initialized objects)
Always catch expected errors only (e.g. KeyError, AttributeError). Otherwise you hide unexpected errors. This is hard to analyze if such an error occurs.

The existence of errors is less to annoy us rather than to provide as many help as possible.

Anyway, the try: except: statement might be the right one for you.
For more help we need to see your code.