OnGUI not recognizing variable change

Ive got a GUI setup to let a player start a game server or to refresh the list of games from the unity master server (case 0). When the player hits “Start Server”, my int variable gameGuiState changes to 1, the join server and refresh buttons disappear like they should as the case is no longer 0. When the player joins a game, the button increments gameGuiState to 1 but the switch doesn’t switch off. I can’t figure this out, I am sure its something completely stupid. It isnt throwing any errors or anything

function OnGUI(){
	
	switch (gameGuiState)
	{
	
	case 0:
		if(GUI.Button(Rect(ButtonX,ButtonY,ButtonW,ButtonH),"Start Server")){		
			Debug.Log("Starting Server");
			StartServer(); //gameGuiState is incremented in this function
		}
			
		if(GUI.Button(Rect(ButtonX,ButtonY * 1.2 + ButtonH,ButtonW,ButtonH),"Refresh")){		
			Debug.Log("Refreshing");
			RefreshHostList();
		}
		if(hostData){
			for (var i : int = 0; i < hostData.length; i++){
				if(GUI.Button(Rect(ButtonX * 1.5 +ButtonW, ButtonY * 1.2 + (ButtonH * i), ButtonW * 3, ButtonH * 0.5), hostData*.gameName)){*

_ Network.Connect(hostData*);_
_
Debug.Log(“JOINING”);_
_
gameGuiState = 1;_
_
}_
_
}_
_
}_
_
}*_

}

I fixed the problem but once again I don’t quite understand why. In the update function I had this:

if(!Network.isClient && !Network.isServer){gameGuiState=0;}

So it looks like the update function was setting gameGuiState back to zero before it actually connected to the game. I just moved this line from update to start.