Respawn System

So I wanna make a Respawn System for my 2D Jump n Run, this is my code for now:

var RespawnY = 4.8;
function Update () 
if(transform.position.y < 2);
{
transform.position = Vector3(-9, -4, RespawnY);
}

What is wrong?

Looks like you’re setting the Y value of the object’s transform to -4 instead of the Z value, effectively making if(transform.position.y < 2) return true forever. Also, you placed a semicolon after that if-statement. Semicolons don’t belong after statement declarations. On top of that, it looks like your Update function doesn’t have enclosing brackets.

Try this instead:

function Update() {
    if (transform.position.y < 2) {
        transform.position = Vector3(-9, RespawnY, -4);
    }
}

Hmm, its not working :confused:

I just ran a test using that exact code and it definitely works…is your script attached to the appropriate object? Is the object’s Y value passing the threshold you set for it to respawn? Are you getting any error messages in the console?

Sorry but i didn’t had time to answer you :(. It’s still not working.
Edit: it’s working i just failed for < and > sorry. ^^

All good, glad you got it working. :slight_smile: