OnTriggerEnter sound problem!!

not sure whats wrong, my sound doesn’t play when I enter the trigger. It plays the minute I press the play button. Please Help!!

Here is my code -

private var hasPlayed : boolean = false;
var Sound : AudioClip;

function OnTriggerEnter() {
	if(!hasPlayed){
		audio.clip = Sound;
		audio.Play();
		hasPlayed = true;
		
	}
}

I think your code is fine, because I tested it out in Unity and seemed to run just fine. Could your problem be that you forgot to uncheck the “Play on awake” box in the properties of your game object in the your sound component?