How to stop following player when dead

hi i made one of the ennemy’s in my game follow the player. But when the player dies i have a error message that says that the ennemy is searching for the player so it cant reload the level

there is my script (its in JavaScript):

 var target :Transform;
 var minRange:int;
 var follow:boolean;
 var speed:float;

 function Update(){
 if(Vector3.Distance(transform.position,target.position)<minRange)
    follow=true;
 if(follow){
    transform.LookAt(target);
    transform.Translate(Vector3.forward *speed* Time.deltaTime);}
 }

How can i make the ennemy stop following the player when he id dead?

When your player dies do you want to reload the level or re-spawn the player because if you want to reload the level there is no need to stop the enemy from following the player, just don’t destroy your player once he dies or make the script call a function in another script using something such as:

void Dead() {
Enemy.GetComponent().ReloadScene(); 
Destroy(gameobject); 
}

Check here for more about calling functions from other scripts : https://forum.unity3d.com/threads/calling-function-from-other-scripts-c.57072/