Getting and error

Im new to programming in general, and just recently started with GUI, so here is my problem:

var GUIon : boolean = false;
var xPos : int;
var yPos : int;
var Height : int;
var Width : int;
var bText : String = "Text in here!";

function Update() {
	if ((Input.GetKeyDown(KeyCode.Escape))  GUIon == false) {
		GUIon = true;
		OnGUI();
	}
	
	if ((Input.GetKeyDown(KeyCode.Escape))  GUIon == true) {
		GUIon = false;
	}
}		

function OnGUI() {
	if (GUIon == true) {
		if (GUI.Button (new Rect(xPos,yPos,Height,Width), bText)) {
			print ("Button Pressed");
		}
	}
}

I get an error that sais “You can only GUI functions from inside OnGUI.”

how do i get rid of it?

You shouldnt call OnGUI() in the Update() method. In fact, in normal circumstances you shouldnt call OnGUI() at all, only override it. Unity will call it for you.

ok thanks for the help

but when i take away the OnGUI(); the script doesnt work, the GUI dont show when i press Escape

Thats because both IF statements in your Update() method will execute in the same frame when Escape is pressed, so GUIon gets immediately set to false right after it was set to true.

ok, i changed the script so that first there is an IF then ELSE IF.

But it still doesnt work

EDIT: nvm got it working. just misspelled one thing.