When "Player" enters a trigger = flashlight off

Hey, I have a Flashlight script:
var lightOfEpicness : Transform;
var clickAudio : AudioClip;

function Start () {
 
 lightOfEpicness.active = false;
 
}
 
function Update () {
        if(Input.GetKeyUp(KeyCode.F)){
                audio.clip = clickAudio;
                audio.Play();
                if(lightOfEpicness.active == true){
                        lightOfEpicness.active = false;
                } else {
                        lightOfEpicness.active = true;
                }
        }
}

and I want it so when I enter a trigger the flashlight goes off.
I tried this but it didn’t work.
var Player : GameObject;
var Script : FlashlightOff = Player.GetComponent(“FlashlightOff”);

	function OnTriggerEnter (other : Collider) {
   
	if(other.collider.tag == Player.tag)
   {
      Script = GetComponent(FlashlightOff);
      Script.enabled = false;
   }
}

You could try adding Static vars To the flashlight script, and setting the flashlight On/Off through a trigger script. For example.

This Script would go on a trigger collider:

function OnTriggerEnter (other : Collider){
if(other.gameObject.tag == "Player") {
FlashLightScript.LightOn = false;
}
}

This Script would go on your flashlight (You will have to rename the script to “FlashLightScript” if you want it to work with the other script, or edit the other script for it to work):

   var lightOfEpicness : Transform;

    var clickAudio : AudioClip;
    
    static var LightOn = false;

function Start () {
 
 lightOfEpicness.active = false;
 
}

function Update () {

if(LightOn == false){
LightOn = true;
lightOfEpicness.active = false;
}

        if(Input.GetKeyUp(KeyCode.F)){
                audio.clip = clickAudio;
                audio.Play();
                if(lightOfEpicness.active == true){
                        lightOfEpicness.active = false;
                } else {
                        lightOfEpicness.active = true;
                }
        }
}

Haven’t tested it, but hope it helps.