OnTriggerEnter Restarts Audio

I was trying to create a trigger zone so that when you pass into a sphere collider with Is Trigger checked, the music starts, and when you exit the music stops. There’s only one problem. If I actually start inside of the sphere collider, and take a step forward, the audio that was already on by ‘play on awake’ stops for a second and the audio restarts. I’m guessing that once I move the OnTriggerEnter Function is called and so it restarts. What way could I could start with the player inside the sphere without the audio restarting once I move?

#pragma strict

private var theCollider: String;

function OnTriggerEnter (other : Collider)
{
	theCollider = other.tag;	
	if(theCollider == "Player")
	{
		audio.Play();
		audio.loop = true;
	}
	
}

function OnTriggerExit (other : Collider)
{
	theCollider = other.tag;	
	if(theCollider == "Player")
	{
		audio.Stop();
		audio.loop = false;
	}
}

Add the audio.Stop() On Enter

Added That Below

private var theCollider: String;

function OnTriggerEnter (other : Collider)
{
    theCollider = other.tag;   
    if(theCollider == "Player")
    {
        audio.Stop();
        audio.Play();
        audio.loop = true;
    }
 
}
 
function OnTriggerExit (other : Collider)
{
    theCollider = other.tag;   
    if(theCollider == "Player")
    {
        audio.Stop();
        audio.loop = false;
    }
}

So someone on another forum gave me the answer to this. Its actually pretty simple to be honest. You Just add ‘!audio.isPlaying’ to the if statement so that even if the function is called, the audio still won’t play.

var Town : AudioClip;

function OnTriggerEnter (other : Collider)
{	 
	var theCollider: String;
	theCollider = other.tag;
    if(theCollider == "Player" && !audio.isPlaying)
	{
		audio.clip = Town;
		audio.Play();
    	audio.loop = true;
	}
	
}

function OnTriggerExit (other : Collider)
{
	var theCollider: String;
	theCollider = other.tag;	
	if(theCollider == "Player") 
	{
		audio.Stop();
		audio.loop = false;
	}
}