checking if gameobject exists

Hi. I use this code to deactivate gameobjects.

GameObject[] rigid;
void Start()		
  rigid = GameObject.FindGameObjectsWithTag("klocek");
	foreach(GameObject rigids in rigid)
	{
		if(rigids.transform.position.x>30)
		rigids.SetActive(false);
	}
}

And then I need to activate them somewhen

void Update(){
  foreach(GameObject rigids in rigid)
  {
	if(rigids.transform.position.x<p1)// if its time to activate you
	rigids.SetActive(true);
  }
}

Everything works untill some of objects get Destroyed. Then I take error: Trying to access gameobject than doesnt exist. Is there a way to avoid this?

Well, instead of destroying them, you could move them of the scene with transform.Translate. Than it would always exist.