Open/Close GUILayout with same key not working

I looked over my code a couple times and it seems like it should work. I am trying to open/close my GUILayout with the same key, like for example pressing esc to open and esc again to close it.

void OnGUI ()
	{
		if (Input.GetAxis ("OpenMenu") != 0) {
						menuOpen = true;
				}

		if (menuOpen == true) {
						// Wrap everything in the designated GUI Area
						GUILayout.BeginArea (new Rect (500, 100, 400, 400));
			
						// Begin the singular Horizontal Group
						GUILayout.BeginHorizontal ();
			
						// Arrange two more Controls vertically beside the Button
						GUILayout.BeginVertical ();
						GUI.Label (new Rect (180, 0, 100, 20), "Menu");
						GUI.Button (new Rect (0, 40, 160, 100), "Save");
						GUI.Button (new Rect (0, 150, 160, 100), "Quit");
						GUI.Button (new Rect (240, 40, 160, 100), "Options");
						GUI.Button (new Rect (240, 150, 160, 100), "N/A");
			
						// End the Groups and Area
						GUILayout.EndVertical ();
						GUILayout.EndHorizontal ();
						GUILayout.EndArea ();
			
						if (Input.GetAxis ("OpenMenu") != 0) {
								menuOpen = false;
						}
				} else if (menuOpen == false){
				}
	}

Also for some reason if I open something else with my game opened in the background the menu will close. Not sure what that is about.

I think your problem is with setting the variable, try this:

if (Input.GetKeyDown(Keycode.key))
{
    if (menuOpen)
        menuOpen = false;
    else
        menuOpen = true;
}

Also, as a side note, there is not need for that ‘else if’, as there is nothing after it.

Edit: I missed something earlier in your code: if you get the input, the menu opens. While the menu is open, if you get the input, it closes. That is the source of your problem.