Destroyed Object Stops Scipt

Hello, I have a script which is meant to turn off other GameObjects components, however when one of the objects is destroyed the scripts stops working for the other objects.


(script works fine)

Other script destroys object1

object2 object3 (script stops working)

I am getting this error with it:

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

Now I have heard about nulling before, but how would I implement it to say “if object1 has been destroyed then skip it and continue the script”?

if(object1 != null)
// Do work on object1