Respawning Problem

I’m kinda new to scripting and i tried to make a respawning script for my game.
But i just can’t get it to work, I only got it to creating thousands and thousand of guys, so many it took ages before i could quit.
What am i doing wrong? here it is:

var Enemy : Transform;

function Update ()
{
if(GameObject.Find(“Robot2”) == false)
{
Invoke(“respawnEnemy”, 5);
}else
{
CancelInvoke();
}
}

function respawnEnemy()
{
var position : Vector3;
for(var i : int = 0; i < 5; i++)
{
position = Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
Instantiate(Enemy, position, Quaternion.identity);
}
}

You should really explain this better. On what object is this script applyed, who is in var Enemy and who is Robot2 and who do you want to instantiate.

Well, I’d have a guess at your “Instantiate(Enemy…)” call isn’t creating a “Robot2” which will make your test “GameObject.Find(“Robot2”) == false” always pass, hence creating a new Enemy every frame.

Try using a tag on your Enemy object and use GameObject.FindByTag instead.

Thanks i figured it out and it works better now