How can I make a script for a flashlight that make sounds when it turns on and off?

Try this:

var key : String;
var onSound : AudioClip;
var offSound : AudioClip;

function Update(){

	if (Input.GetKeyDown(key)){
	
		if (light.enabled == true)
			light.enabled = false;
			audio.PlayOneShot(offSound);
		else
		
			light.enabled = true;
			audio.PlayOneShot(onSound);
		}
}