Adding a timer to make a win/loss condition

Hello, I am trying to make a drop down game that requires the player to keep their score between a certain set of numbers. That I have figured out, what I need help with is that I want a timer to start when the player gets outside of the pre determined range and if the player get his score back within the range I want the timer to stop and reset letting play continue. The loss condition is loading another level btw if that help for any reason.

//Drew Hilvers
var redStyle : GUIStyle; //style for redtext
var greenStyle : GUIStyle; //style for greentext
var scoreStyle : GUIStyle; // style for overall score
var countDownIsActive : boolean; // boolean for whether or not timer should be running
  
function Update()
{
	if(PlayerStatus.count > 12  || PlayerStatus.count < 8  countDownIsActive == false)
	{
	countDownIsActive = true;
	}
	

	if(PlayerStatus.count <= 12 || PlayerStatus.count <= 8  countDownIsActive == true)
	{
	countDownIsActive = false;
	}

	Debug.Log(countDownIsActive);
	
	if (countDownIsActive == true;)
	{
		yield WaitForSeconds(5);
		Application.LoadLevel("lost");
	}
}	
	




function OnGUI ()
{
	GUI.Label (Rect (450,40,100,100), "" + PlayerStatus.score, scoreStyle);

	if(PlayerStatus.count <= 12 || PlayerStatus.count <= 8)
	{
	GUI.Label (Rect (10,40,100,100), "" + PlayerStatus.count, greenStyle);
	}
	
	if(PlayerStatus.count > 12  || PlayerStatus.count < 8)
	{
	GUI.Label (Rect (10,40,100,100), "" + PlayerStatus.count, redStyle);
	}
	
}

The error I get now is that if you get back in range before the 5 seconds run out you still lose and go to the “lost” level.

Double-check this line:

if(PlayerStatus.count <= 12 || PlayerStatus.count <= 8  countDownIsActive == true)

It looks like you might have a typo.

I double checked my typing(should have just copied and pasted like this time) and this is my current script that has no errors just doesn’t do what I would like it to.

//Drew Hilvers
var redStyle : GUIStyle; //style for redtext
var greenStyle : GUIStyle; //style for greentext
var scoreStyle : GUIStyle; // style for overall score
var countDownIsActive : boolean; // boolean for whether or not timer should be running
  
function Update()
{
	if(PlayerStatus.count > 12  || PlayerStatus.count < 8  countDownIsActive == false)
	{
	countDownIsActive = true;
	}
	

	if(PlayerStatus.count <= 12  PlayerStatus.count >= 8  countDownIsActive == true)
	{
	countDownIsActive = false;
	}

	Debug.Log(countDownIsActive);
	
	if (countDownIsActive == true)
	{
		countdown();
	}
}	
	
function countdown()
	{
		yield WaitForSeconds(5);
		Application.LoadLevel("lost");
	}
	




function OnGUI ()
{
	GUI.Label (Rect (450,40,100,100), "" + PlayerStatus.score, scoreStyle);

	if(PlayerStatus.count <= 12  PlayerStatus.count >= 8)
	{
	GUI.Label (Rect (10,40,100,100), "" + PlayerStatus.count, greenStyle);
	}
	
	if(PlayerStatus.count > 12  || PlayerStatus.count < 8)
	{
	GUI.Label (Rect (10,40,100,100), "" + PlayerStatus.count, redStyle);
	}
	
}

I actually solved my own problem here is the script finished and working correctly

//Drew Hilvers
var redStyle : GUIStyle; //style for redtext
var greenStyle : GUIStyle; //style for greentext
var scoreStyle : GUIStyle; // style for overall score
var countDownIsActive : boolean; // boolean for whether or not timer should be running
static var count : int;
var timeToDie : int;

  
function Update()
{
	if(PlayerStatus.count > 12  countDownIsActive == false  || PlayerStatus.count < 8  countDownIsActive == false)
	{
	countDownIsActive = true;
	countdown();
	}
	

	if(PlayerStatus.count <= 12   PlayerStatus.count >= 8  countDownIsActive == true)
	{
	countDownIsActive = false;
	}
	
	if(countDownIsActive == false)
	{
		count = 0;
	}

	Debug.Log(count);
	
	if (count == timeToDie)
	{
		Application.LoadLevel("lost");
	}
	
	

function countdown()
{
	count = 0;
	yield WaitForSeconds(1);
	count ++;
	yield WaitForSeconds(1);
	count ++;
	yield WaitForSeconds(1);
	count ++;
	yield WaitForSeconds(1);
	count ++;
	yield WaitForSeconds(1);
	count ++;
	yield WaitForSeconds(1);
	count ++;
	yield WaitForSeconds(1);
	count ++;
	yield WaitForSeconds(1);
	count ++;
}


function OnGUI ()
{
	GUI.Label (Rect (450,40,100,100), "" + PlayerStatus.score, scoreStyle);

	if(PlayerStatus.count <= 12  PlayerStatus.count >= 8)
	{
	GUI.Label (Rect (10,40,100,100), "" + PlayerStatus.count, greenStyle);
	}
	
	if(PlayerStatus.count > 12  || PlayerStatus.count < 8)
	{
	GUI.Label (Rect (10,40,100,100), "" + PlayerStatus.count, redStyle);
	}
	
}