Why is this counter not working?

var currentScore : int = 0;
var addScore : int = 10;
var finalScore : int = 0;

function OnTriggerEnter(collision : Collider){

if(collision.gameObject.tag == "TimeCapsule"){

Counter();


Destroy(collision.gameObject);
}

function Counter(){

currentScore += addScore;
finalScore = currentScore;

}

the final score is always 10 even when it collects the object

currentScore (0) += addScore (10) => currentScore will be 10, so will be your finalScore

Have you done numerous collisions or checks with no collisions?

Do you try use this way?

if (`currentScore  <= ``finalScore `)
{

}

but when it does it a second time wont currentScore be 10 so + addScore what is 20 and then finalScore = 20???

You are disabling the collision after they hit, so the final score will never be more than 10 since you are not allowing it to be hit again. Since you are not doing anything with final score, why not just remove it since your example is just increasing the final score total but it’s always going to be the same as your current score. Unless your final score is suppose to be updated multiple times then you would need to stick your final score variable into another script and access it.