Odd parenthesis expectation

So I have a script

    #pragma strict
     
     function Update(){
  
     var enemyStats : Stats = gameObject.GetComponent(Stats);
     
     if(Input.GetKey("space")){
     	function OnGUI();{
     	GUI.Box();{Rect(0,0,10,10); "Your mom, unity";};
     	};
     
     
     
     
     };
     }

It’s saying on line 8 (The one with the OnGui function) it’s expecting a ( instead of OnGui.

Sorry I’m asking 3 thousand questions, I’m just dumb.

Delete line 8 you don’t need it. Your OnGui function starting at line 12 should be all caps

function OnGUI{
}

It looks as if you are trying to call OnGUI, you don’t need to do this it will be called multiple times per frame for you.

#pragma strict
 
var enemyStats : Stats = gameObject.GetComponent(Stats);
var showBox : boolean  = false; 

function Update(){
	if(Input.GetKeyUp("space")){
		showBox = !showBox;
	}
}
 
function OnGUI(){
	if(showBox)
		GUI.Box(Rect(20,20,100,100),"This is a title");
}

I assumed you were trying to show/hide the box when you pressed the space key?

You have your script backwards, you can’t declare a function inside an if statement, the correct format should be:

#pragma strict

var enemyStats : Stats = gameObject.GetComponent(Stats);

function Update(){

if(Input.GetKey("space")){
OnGUI();
}
}

function OnGui(){
GUI.Box(Rect(0,0,10,10),"This is a title");
}

1-The variables should be declared outside of functions unless you want them to exist only when that function is being called (which for the most part you wont want to).

2-You have to end each statement with a Semicolon, but you dont (and shouldn’t) add them after a curly bracket.

3-You cant declare a function inside another function. If you want to specify what your OnGui function will do declare separately from the Update function.
Look at my script, I have two separate functions, Update and OnGui, inside Update Im saying that if you press the key assigned to the “space” input then it will run the OnGui function (no need to specify it’s a function here).

4-Check information on setting up custom input buttons, my guess is that you are trying to use the spacebar to test this script, but unless you go to the input manager, create a new input called “space” and assign a key to it it wont work, if you want to use a specific key the use:

Input.GetKeyDown(KeyCode.Space)