GUILayout.Button staying true?

hey i got this piece of code to load a MultiPlayer map

if (!iWantToSetupAServer  connected )
			{
			GUILayout.Label("Select a Level");
			scrollPosition=GUILayout.BeginScrollView (scrollPosition);
			foreach(string level in levels)
			{
				if (GUILayout.Button(level))
				{
					networkView.RPC( "LoadLevel", RPCMode.AllBuffered, level, lastLevelPrefix + 1);
					connected=false;
				}

and this in a ServerDisconnectWindow

if(GUILayout.Button("Change Map"))
		{
			Application.LoadLevel(0);
			connected = true;
		}

but if the second button set connected to true so that the choose level window appears, it only appears for a second and then goes back to the ServerDisconnectWindow? as if the button in the first part of code stay true or pushes itself :wink:
anyway any idea how this can happen… these are the only 2 parts where the connected bool gets changed.

ok so i found out that it’s because I reload the server level and destroy my multiplayerManager with this code attached. so i added a
void Awake() {
DontDestroyOnLoad(transform.gameObject);
}

but now i get a whole bunch of multiplayerManager objects on each load of a map, is there any DontLoadThisOnLoad?

edit: never mind this is not the way to go… i need to set my bools back to the state when i choose a level and need to keep my instantiated players on the clients… hmm maybe my levels and level mesh are called the same so i could remember the name of the loaded level and look for the gameobject with that name and just destroy that… lets try :slight_smile:

getting these 3 errors:
View ID AllocatedID: 1 not found during lookup. Strange behaviour may occur

Couldn’t perform remote Network.Destroy because the network view ‘AllocatedID: 1’ could not be located.

NullReferenceException
UnityEngine.GameObject.GetComponent[NetworkView] () (at C:/BuildAgent/work/b0bcff80449a48aa/Runtime/ExportGenerated/Editor/UnityEngineGameObject.cs:18)
MultiplayerScript.resetLevel (NetworkViewID viewID) (at Assets/MyAssets/scripts/multiplayerScripts/MultiplayerScript.cs:385)

with this:

(GUILayout.Button("Change Level"))
		{
			NetworkViewID viewID = Network.AllocateViewID();
			networkView.RPC( "resetLevel", RPCMode.AllBuffered, viewID);
			connected = true;
		}
	
	[RPC]
	void resetLevel (NetworkViewID viewID)
	{
		print (levelOnServer);
		
		GameObject currentLevel = GameObject.Find(levelOnServer);
		NetworkView nView;
        nView = currentLevel.GetComponent<NetworkView>();// last error brings me to this
		print (nView);
        nView.viewID = viewID;
		//if(networkView.isMine)
		Network.Destroy (viewID);

}

also the print (levelOnServer); returns null.

please if some one could explain to me what happens here, i really suck at understanding these RPC… :frowning:
wish i was could code for real instead of my clumsy copy/paste - trail and error way…