If statement not reading variable

Hey i have cube which is a “win” and a sphere which is the “goal”
The idea is you pick up the win cube and then that opens the goal, and you can go in. The first collision detection works finde and the cube destroys properly and eerything, but the second, with “if(goalopen ==true)” does not.

The code works perfectly well if i delete the “if(goalopen ==true)” statement, but then you can go directly to the goal without picking up the cube, which is not what i want…

I would really appreciate if anyone could point out my mistake, thanks in advance! :slight_smile:

#pragma strict
var guiWin : GUIText;
var score; 
var target : lysskifte;
var target2 : lyskifte2;
var goalopen;

function Start () {
	guiWin.text = " ";
	var score = false;
	var goalopen = false;
}

function Update () {

}

function OnTriggerEnter(col : Collider){
	if(col.collider.name == "win"){
		guiWin.text = "Cube Collected";
		print("collison detected");
		var score = true;	
		print(score);
		target.score = true;
		target2.score = true;
		var goalopen = true;
		Destroy(col.gameObject);
		yield WaitForSeconds(3);
		guiWin.text = "";
	}
      else if(col.collider.name =="goal"){
		if(goalopen == true){
			Destroy(col.gameObject);
			guiWin.text = "You Win";
			print("goal!");
			yield WaitForSeconds(6);
			guiWin.text = "";
			}
		}
}

Change this:

function OnTriggerEnter(col : Collider){
    if(col.collider.name == "win"){
       ...
       var goalopen = true;
       ...
    }
    ...
}

to this:

function OnTriggerEnter(col : Collider){
    if(col.collider.name == "win"){
       ...
       goalopen = true;
       ...
    }
    ...
}