Two GUI popups - 1st one needs to be destroyed

I was wondering how I would work out the following situation: I have an NPC that generates a GUI depending on a particular variable. However, the following code generates both GUI’s rendering at the same time… by both I mean: there’s one that should appear when the variable no_coop_button is set to true and another to appear when the npc_trigger is set to true. I’m not sure how to generate these GUI’s separately.

function OnGUI()
{
	if (no_coop_button)
	{
		GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
		GUI.Box (Rect(0, 0, 100, 100), "You are \n a thief");
		GUI.EndGroup ();
	}

	if (npctrigger)
	{
	GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
	}
	
	if (yesbutton)
	{
		GUI.Box (Rect(0, 0, 100, 100), "Enter \n treasure \n chest");
		Destroy(this, 5.0f);
	}
	
	else if (nobutton)
	{
		GUI.Box (Rect(0, 0, 100, 100), "You \n cannot \n enter");
		Destroy(this, 5.0f);
	}
	
	else
	{
		GUI.Box (Rect(0, 0, 100, 100), "Give inventory?");
		if (GUI.Button (Rect(25, 25, 50, 30), "Yes"))
		{
			yesbutton = true;
			Debug.Log("True");
		}

		if (GUI.Button (Rect(25, 65, 50, 30), "No"))
		{
			nobutton  = true;
			Debug.Log("No");
		}
	}
	GUI.EndGroup ();
}

The npctrigger check only outputs one line :

GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));

Which doesn’t do anything visually, even though you said that it’s supposed to show up a menu.

The rest of your checks (yesbutton, nobutton and else) are outside the two if statements at the top. Nest them at their appropriate place.