Issue with OnGUI close button.

Im following a simple tutorial from:

I can make the inventory window appear and disapear using the Inventory Button, but when I try to implement a Close button the window wont open. If I comment out the InventoryOn = false; inside of the close buttons brackets the window and the button show up, but of course the button does nothing. If I have the buttons functionality enabled it seems to just close automatically. I’ve tried adding && mousebutton 0 down etc to the if statement for the button, things to only allow it if its already on, but it doesnt seem to care and just closes it before it shows up. I’m guessing that having the button created automatically runs the function to close it but that makes no sense as it’s a simple unity based OnGUI button and hasnt been clicked. Anyone have any idea why this might be happening because it doesnt make any sense and shouldn’t be happening.

private var InventoryOn = false;

var ClosePos : Vector2 = new Vector2(290, 320);
var WindowSize : Vector2 = new Vector2(360, 360);
var CloseSize : Vector2 = new Vector2(64, 64);

var InventoryWindow : Texture;
var CloseButton : Texture;


function Update()
{
	if((Input.GetButtonDown("Inventory")) && !InventoryOn)
	{
			InventoryOn = true;
	}
	else if((Input.GetButtonDown("Inventory")) && InventoryOn)
	{
			InventoryOn = false;
	}
}

function OnGUI()
{
	if(InventoryOn)
	{
		GUI.BeginGroup(new Rect((Screen.width - InventoryWindow.width) / 2 + 330, (Screen.height - 
        InventoryWindow.height) /2 + 325, WindowSize.x, WindowSize.y), InventoryWindow);
		
			if(GUI.Button(Rect(ClosePos.x, ClosePos.y, CloseSize.x, CloseSize.y), CloseButton));
			{
				InventoryOn = false;
			}
		
		GUI.EndGroup();
	}
}

I know that the close button is uneccesary since you can press Inventory again and that works fine, but I’m concerned that future buttons will have this same “automatically enabling” problem. I can add another check inside of the GUI button brackets of
if mouse button not pressed" else if mouse button pressed and it will show, but then clicking anywhere turns it off.

Remove this semicolon

CloseButton)); // right there