Moving first person controller via script

Hello, I’m new to using unity and am looking forward to getting my hands dirty, but first I’m following along with a short tutorial series.

I’m at a point where I’m writing a small script “catch” a player when they fall off the edge of the terrain, and move them to the starting location. However, the script is not actually moving the player.

Here’s the code (javascript):

function Update () 
{
    if ( transform.position.y < -50 ) {
        transform.position.y = 2;
        transform.position.x = 0;
        transform.position.z = 0;

        //Send verification to console
        print ( "Player fell, resetting to start." );
    }
}

When I hit play and run the player off the edge, I can see the code firing off in console, but I just keep falling. I’ve attached the script to the player fab and can see it in inspector when I click the player. Can anyone see what I’ve done wrong?

There’s nothing wrong with your code. I’ve just tested it in a project which uses the First Person Controller, and it worked as expected. But I tested a hypothesis: I attached the script to Graphics, a First Person Controller’s child, and the player fell continuously, while the Graphics child was “jumping” to the initial position each time the limit was reached. Could it be your problem? Check if the script is attached to the First Person Controller or to one of its children (Graphics or Main Camera).