How do you turn off a script if it comes out an error.

I have a script to point a game object to empties in a sequence. What it does is it checks an attribute, to see what it is. Say its 5. and then it serches for “OBPointer.005” but as you raise the attribues value, it is going to fail because eventualy there will be no object with that name. As because it fails it ends up running this script, an endless amount of times, and it is slowing down my game.

In a nutshell:
Is there a function that says,

if “error”
Do this

else:

do this

that’s my plan to solve this but i don’t know what i sould put for “error”

thanks

maybe you could use try catch possibility of Python!?

You could always try to see if the object exists before you operate upon it (i.e. check the attribute).