Game is instantly going to main menu when i restart level

I think i know what the problem is but when i tried changing the “Lives” of the player back to 3 just before the restart button is pressed it doesnt work. Im probably changing the lives back to the default 3 wrong.

Basicly how my game works is if the lives of the player less than or equal to 0 the game goes to the “game over scene”.

This is how my code looks in MainMenu script.

function OnGUI()
{
	//make a group on the center of the screen
	GUI.BeginGroup(Rect(Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 175));
	
	//Make a box to see the group on screen
	GUI.Box(Rect(0,0,100,175), "Main Menu");
	
	//add buttons for game navigation
	if(GUI.Button(Rect(10,30,80,30), "Start Game"))
	{
		var liveScript = 3;
		liveScript = GetComponent("scriptPlayer").lives;
		Application.LoadLevel("scene1");
	}

and this is how i assigned var lives in scriptPlayer.

static var lives				:	int		= 3;

For some reason this just breaks my “start game” button and doesnt start the game. If anyone could help me it would be much appreciated.

The problem might be that you setup your game menu to load every time you start the level when you just start playing the game but as you reload the level then thee game acts as if it is loading the level for the first time again.

Try making it that you have a separate scene for the menu and this will just load the level that you will be playing. I know this isn’t the most practical way but it is a solution.

function Update()
{
GetComponent(scriptPlayer).lives = 3;
}

Yay i got it to work. thanks for taking the time to try and help me.