problem with enable/disable on health script

so I have a modified version of my health script that a user in the community had edited for me in a different question. The script is pretty much fine but I am having issues with the enable and disable parts of the scritpt. What I wanted to do is when the player dies it will temporarily disable and when the player respawns it will enable again. However when the player dies nothing happens the health variable continues to take damage and end up on a negative number. Is there a better way to achieve the same or similar results?

here is the script

 var PointCube: Transform;
 var spawneffect: Transform;
 var deatheffect: Transform;
 var SpawnPoints: Transform[];
 private var SpawnPoint: Transform;
 
 //Respawn timer for the coroutine
 var respawnTime: float = 3;
 
 var respawn: boolean = false;
 
 //This is the players current health
 var health: float = 100;
 
 //The max health the player is spawned with

 var healthText: UI.Text;
 
 //At start set the players health to maxHealth
 function Start() {
     health = 100;
 }
 
 function Damage(dmg: float) {
     health -= dmg;
 }
 
 function Update() {
     if (healthText) {
         healthText.text = health.ToString();
             // If the players health is zero start the respawn function
         if (health <= 0) {
 yield Respawn();
         }
     }
 }
 
 //This is a coroutine. Basically meaning it has a special wait timer function
 function Respawn() {
     //temporarily disable player
     gameObject.SetActive (false);


     Instantiate(deatheffect, transform.position, transform.rotation);
     Instantiate(PointCube, transform.position, transform.rotation);
 
     //Wait for the respawnTimer. (This is the special wait timer I was speaking of)
     yield WaitForSeconds(respawnTime);
 
     //Find a random spawn point
     var spawnPointID: float = Random.Range(0, SpawnPoints.length);
 
     //Set the player at that random spawn point
     transform.position = SpawnPoints[spawnPointID].position;
 
     //enable player
     gameObject.SetActive (true);


     Instantiate(spawneffect, transform.position, transform.rotation);
 
     var audio: AudioSource = GetComponent.<AudioSource>();
     audio.Play();
     audio.Play(44100);
 
     //change this to set float not add to it
     health = 100;
 }

Make sure the value is never negative:

function Damage(dmg: float) 
{
      health -= dmg;
     if (health < 0) { health = 0; }
}

But are you sure your code works? Coz you are disabling the game object so the coroutine won’t run.

You 'd need to disable the rendering and collider only