Will not detect points! What is wrong with this code?

Hey!
I have tried to add points to my game in unity, but it wont add them.

    var score = 1;
    var scoreText = "Score: 0";
    var mySkin : GUISkin;
    
    function OnTriggerEnter( other : Collider ) {
        Debug.Log("OnTriggerEnter() was called");
        if (other.tag == "Coin") {
            Debug.Log("Other object is a coin");
            score += 1;
            scoreText = "Score: " + score;
            Debug.Log("Score is now " + score);
            Destroy(other.gameObject);
        }
    }
    
    function OnGUI () {
        GUI.skin = mySkin;
        GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString());
    }

Whats wrong with this code?

You are accumulating score without it displaying in your GUI.

Your string for the GUI only shows what it says: “Score: 0” To fix this, first remove the zero. Then, in the GUI.Label, put the variable for your score string (you do not need the other operation for the string to appear) and put “+score.” You also can remove the scoreText in the Update function.

It should look like this:

 var score = 1;
    var scoreText = "Score: ";
    var mySkin : GUISkin;
    
    function OnTriggerEnter( other : Collider ) {
        Debug.Log("OnTriggerEnter() was called");
        if (other.tag == "Coin") {
            Debug.Log("Other object is a coin");
            score += 1;
            //Removed scoreText here.
            Debug.Log("Score is now " + score);
            Destroy(other.gameObject);
        }
    }
    
    function OnGUI () {
        GUI.skin = mySkin;
        GUI.Label (Rect (10, 10, 500, 200), scoreText + score);
}

If, for some reason, this doesn’t work, try completely eliminating “scoreText” and put the string directly in the GUI.Label.

GUI.Label(Rect(10, 10, 500, 200),"Score: "+score)