Kill/Death script not working...

So I’ve coded my very first thing ever in JS and it doesn’t seem to work? Kinda new to JS scripting but this script right here goes on the Player.

#pragma strict

var currentDeaths : int = 0;

function OnGUI()
{
    GUI.Box(Rect(5, 180, 50, 20), "Deaths");
    GUI.Box(Rect(54, 180, 40, 20), "" + currentDeaths);
}

This code goes on the block/gameObject that’ll kill him but it seems to not work?

#pragma strict

private var material : DeathScript;

function Start()
{
    material = GameObject.Find("First Person Controller").GetComponent(DeathScript);
}

function OnTriggerEnter(Col : Collider)
{
    if(Col.tag == "Player")
    {
        Destroy(gameObject);
        material.currentDeaths++;
        Application.LoadLevel("Scene2");
    }
}

Move the destroy to the end.

given that the actual destroying of a game object happens at the end of the current frame I don’t think that will make much difference.

You are loading Scene2, which is going to destroy everything and load the new scene, that includes the first script and the game object it is attached to.

You might want to look into Unity - Scripting API: Object.DontDestroyOnLoad

Let me try…