FPSTutorial: AI robot not taking any damage!

Hello well, this is my script. I have gotten an answer to remove the if (hitPoints <= 0.0) part. But, which one? I have been asking this question alot but i never seem to get any help!

var breakpoints = 100.0;
var deadReplacement : Transform;
var dieSound : AudioClip;

function ApplyDamage (damage : float) {
	// We already have less than 0 hitpoints, maybe we got killed already?
	
	hitPoints -= damage;
	if (hitPoints <= 0.0)
	{
		Detonate();
	}
}

function Detonate () {
	// Destroy ourselves
	Destroy(gameObject);
	
	// Play a dying audio clip
	if (dieSound)
		AudioSource.PlayClipAtPoint(dieSound, transform.position);

	// Replace ourselves with the dead body
	if (deadReplacement) {
		var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation);
		
		// Copy position & rotation from the old hierarchy into the dead replacement
		CopyTransformsRecurse(transform, dead);
	}
}

static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
	dst.position = src.position;
	dst.rotation = src.rotation;
	
	for (var child : Transform in dst) {
		// Match the transform with the same name
		var curSrc = src.Find(child.name);
		if (curSrc)
			CopyTransformsRecurse(curSrc, child);
	}
}

if (hitPoints <= 0.0)
{
Detonate();
}
else {
hitPoints -= damage;
}

The script above do nothing alone: some robot part must send the message “ApplyDamage” for this to work. I suspect you don’t have any script doing this, so let’s create one:

function Update(){
  if(Input.GetMouseButtonDown(1)){ // if the RIGHT button pressed
    // casts a ray from the mouse pointer
    var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    var hit: RaycastHit;
    if(Physics.Raycast(ray, hit)){ // if something hit, send the message
      hit.collider.SendMessageUpwards("ApplyDamage", 20, SendMessageOptions.DontRequireReceiver);
    }
  }
}

Attach this script to your player and run the game. Click the robot with the RIGHT button and a 20 points damage will be applied. After 5 clicks, the robot will die.

This script creates a ray perpendicular to the screen starting from the mouse pointer. If something is hit, it sends the message (“ApplyDamage”, 20) to the hit collider owner.

The machine gun uses the same idea to apply damage. I strongly suggest that you download the FPS tutorial and follow its steps one after one.