(C#) changing an object variable from another object

I have an object with a script that has a bool variable and I want to change that variable using a script from a trigger object. So when the player enters the trigger the trigger set’s the object’s bool variable to true and when the player leaves the trigger sets it to false.

Here’s what I have so far:

public Transform target;
Void OnTriggerEnter(Collider hit){
   if (hit.tag == "Player"){
      script = target.GetComponent<ScriptName>();
      script.boolvar = true;
   }
}
Void OnTriggerExit(Collider hit){
   if (hit.tag == "Player"){
      script = target.GetComponent<ScriptName>();
      script.boolvar = false;
   }
}

the error message is saying that “script” dose not exist in the current context, but I have no idea how to declare it.

You don’t have a type definition for “script”. should be -

ScriptName script = target.GetComponent();

ah yes I’ve been trying different versions of that but I guess I never tried it with the brackets at the end. Thanks.