Trouble disabling and enabling script via another script

So basically, I am trying to create a trigger script that when entered will turn the players flashlight off, then after 4 seconds, turn it back on again. It also needs to be able to disable the players flashlight script so they cannot enable the flashlight manually before these 4 seconds have passed. I’m not sure how to reference other scripts via script, so I’m not too sure what I need to do to get this right, but here is my code so far (everything works as intended but this). The flashlight script that I am attempting to reference is called flashlight:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TriggerScriptFlashlightKill : MonoBehaviour 
{

	public AudioClip scareSound;

	public GameObject triggerZone;

	public Light lightSource;

	public GameObject script;

	private bool hasPlayed = false;

	AudioSource scareAudio;

	private flashlight flashlightScript;

	void Start ()
	{
		scareAudio = GetComponent<AudioSource> ();
		triggerZone = GetComponent<GameObject> ();
		flashlightScript = script.GetComponent("flashlight") as flashlight;
	}

	void Update ()
	{

	}

	void OnTriggerEnter(Collider other)
	{
		if (other.gameObject.CompareTag ("Player")) 
		{	
			if (!hasPlayed) 
			{
				scareAudio.PlayOneShot (scareSound);
				hasPlayed = true;
				StartCoroutine(FlashlightFlicker());
				Destroy (triggerZone.gameObject);
			}
		}
	}
	IEnumerator FlashlightFlicker()
	{
		flashlightScript.enabled = false;
		lightSource.enabled = false;

		yield return new WaitForSeconds (4);

		flashlightScript.enabled = true;
		lightSource.enabled = true;

	}
}

Try this :

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TriggerScriptFlashlightKill : MonoBehaviour 
 {
 
     public static TriggerScriptFlashlightKill instance {get; set;}
     public AudioClip scareSound;
 
     public GameObject triggerZone;
 
     public Light lightSource;
 
     public GameObject script;
 
     private bool hasPlayed = false;
 
     AudioSource scareAudio;
 
     private flashlight flashlightScript;
 
     void Start ()
     {
         instance=this;
         scareAudio = GetComponent<AudioSource> ();
         triggerZone = GetComponent<GameObject> ();
         flashlightScript = script.GetComponent("flashlight") as flashlight;
     }
 
     void Update ()
     {
 
     }
 
     void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.CompareTag ("Player")) 
         {    
             if (!hasPlayed) 
             {
                 scareAudio.PlayOneShot (scareSound);
                 hasPlayed = true;
                 StartCoroutine(FlashlightFlicker());
                 Destroy (triggerZone.gameObject);
             }
         }
     }
     IEnumerator FlashlightFlicker()
     {
         flashlightScript.enabled = false;
         lightSource.enabled = false;
 
         yield return new WaitForSeconds (4);
 
         flashlightScript.enabled = true;
         lightSource.enabled = true;
 
     }
 }

Now use this instance to acess any public method or variable from this class eg. TriggerScriptFlashlightKill.instance.scareSound;

Okay… thank you both for being so patient! I finally got it to work (somehow)! Thank you both again :slight_smile:
I’ll show you both scripts:
Flashlight:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; //this allows us to reference anything to do with the UI in our script. *MUST BE ADDED IN ORDER TO USE UI IN SCRIPTS*

public class flashlight : MonoBehaviour 
{

	public Light lightSource; //allows us to add a light source to be toggled.
	public AudioClip soundOn; //allows us to add a sound to be played everytime the flashlight is toggled.
	public AudioClip soundOff;
	public float maxBatteryLife;
	public float drainSpeed;
	public KeyCode key; //this will allow us to choose our desired key to toggle the flashlight outside of the script.
	public Text isontext; //this is used as a reference to the text that will be updated by our script.
	private bool isOn = false; //this will make the text display the light as being off at the beginning of the game, rather than displaying nothing.
	AudioSource lightaudio;
	public bool scriptEnable = true;

	void Awake () //awake is used to initiate game states and variables before the game starts - this is only ran once during the script's lifetime. We only need to grab the audio source once, so we used awake to do so before anything else can happen.
	{
		lightaudio = GetComponent<AudioSource> (); //grabs the audio source component - allows sound to be played.
	}

	void Start () //Start is called on the frame when a script is enabled just before any of the Update methods is called the first time.
	{
		lightSource.enabled = false; //this will start the game with the flashlight off.
		//displaytext();
	}

	void Update () //anything within the update function will be called/updated every frame.
	{
		if (scriptEnable == true) 
		{
			if (Input.GetKeyDown (key)) 
			{ //if the specified key (set in the Inspector) is pressed, then do the following
				isOn = !isOn; //the boolean isOn will be toggled when the specified key is pressed.
				//displaytext();
				playsound ();
			}
			if (isOn) 
			{
				lightSource.enabled = true; //the "!" operator means not, you can toggle something by setting it to the opposite value of itself, which is what we are doing here with the light source. You can toggle a light source by toggling its enabled state.

			} else 
			{
				lightSource.enabled = false;
			}
		} else 
		{	
			scriptEnable = false;
		}
	}
	void displaytext () //using the same line of code more than once in inefficient, therefore I made the line of code a function, so instead of using that same line of code, I can call the function. This uses less memory.
	{
		isontext.text = "Light: " + isOn.ToString (); //the boolean variable isOn will be displayed on the screen whether it is true or false (testing text).
	}
	void playsound () //this function allows us to play a different sound when the flashlight is toggled on or off.
	{
		if (lightSource.enabled == true) //if the flashlight is on, then play the sound indicating that the flashlight has been toggled on.
			lightaudio.PlayOneShot (soundOn);
		if (lightSource.enabled == false) //if the flashlight is off, then play the sound indicating that the flashlight has been toggled off.
			lightaudio.PlayOneShot (soundOff);
	}
}

TriggerScriptFlashlightKill:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TriggerScriptFlashlightKill : MonoBehaviour 
{

	public static TriggerScriptFlashlightKill instance {get; set;}

	public AudioClip scareSound;

	public GameObject triggerZone;

	public Light lightSource;

	public GameObject script;

	private bool hasPlayed = false;

	AudioSource scareAudio;

	private flashlight flashlightScript;

	void Start ()
	{
		instance = this;
		scareAudio = GetComponent<AudioSource> ();
		triggerZone = GetComponent<GameObject> ();
		flashlightScript = script.GetComponent<flashlight>();
	}

	void Update ()
	{
	}

	void OnTriggerEnter(Collider other)
	{
		if (other.gameObject.CompareTag ("Player")) 
		{    
			if (!hasPlayed) 
			{
				scareAudio.PlayOneShot (scareSound);
				hasPlayed = true;
				StartCoroutine(FlashlightFlicker());
				Destroy (triggerZone.gameObject);
			}
		}
	}
	IEnumerator FlashlightFlicker()
	{
		flashlightScript.scriptEnable = false;
		lightSource.enabled = false;

		yield return new WaitForSeconds (4);

		flashlightScript.scriptEnable = true;
		lightSource.enabled = true;
	}
		
}