Press button if you are inside a trigger (Sorry)

FIRST of all im sorry for all the things i’ve said recently i was just getting a little worked up because java is very frustrating since i have just got into it . thank you for the help i’m getting , any help will be appreciated.

SO my question is , how come this says ou can only call GUI functions from inside OnGUI?

var Switch : GameObject;
Switch = gameObject.FindWithTag("switch");


function OnTriggerEnter (other : Collider) {

  if(other.tag == "Player"){
     
    OnGUI ();   
  }
}


function OnGUI (){

  if(GUI.Button(Rect(100,100,100,100),"Click to play")){
      Switch.animation.Play("Bridge");
  

}


}

And also the Gui button appears even when im not inside the trigger . Feel free to edit my question if it will help me.

if(other.tag == “Player”)
{
OnGUI();
}

You have this function call to OnGUI() in a trigger. OnGUI() will get called several times per frame just from including the function.

Instead, enable/disable the element, perhaps by toggling a boolean declared with the rest of your variables.