Making a sound play once on collision, can you fix my script?

Hello Unity Answers,
I have collected some script from the internet and have tried to put it together. Unfortunately, I am new to coding and I don’t even know how to lay it out properly. Would anybody care to fix it for me? It plays a sound when I enter an area, but I have broken it trying to make play once (so if you go back in said area it doesn’t play again). Thanks!

#pragma strict

var scareSound:AudioClip;
var hasPlayed = false;

function OnTriggerEnter(o:Collider){

audio.PlayOneShot(scareSound);

if(!hasPlayed){hasPlayed = true;

}

Try this:

Add a AudioSource to the object with the script attached and uncheck play on awake and select your clip as the audio clip, then add this script:

#Pragma strict

function OnTriggerEnter(o : Collider){
    AudioSource.Play();
    Destroy (this);
}

Delete the audio source or if you don’t need that trigger anymore, delete the whole gameobject. Google how to do these.