Enemy health script using raycast not destroying tagged object

So I have this code

var Health = 100;
 public static var cHealth = 100;
 var HealthD : GUIText; 
 function Start() {
     DisplayAmount();
 }
 function DisplayAmount () {
     HealthD.text = ""+ cHealth;
 }
function Update () 
{
    // if you press Mouse Button
    if (Input.GetMouseButtonDown(0)){ // if you press Left Mouse Button -> GetMouseButtonDown(0) 
        var hit: RaycastHit;
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition); // it sends a ray from Camera.main
        if (Physics.Raycast(ray, hit)){ // if it hits something 
        	if (hit.collider.gameObject.tag == "beep"){        
        		cHealth += -10;
         		HealthD.text = ""+ cHealth;
         		if (cHealth <= 0){
         			if (hit.collider.GameObject.tag == "beep"){
         				DestroyObject(gameObject);
         			}
         		}
     		}
 		}
    }

And when the enemies health gets to 0, I get the error:

“NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)
raycast.Update () (at Assets/raycast.js:21)”

rather than the object being destroyed. I used to have the code like this:

var Health = 100;
 public static var cHealth = 100;
 var HealthD : GUIText; 
 function Start() {
     DisplayAmount();
 }
 function DisplayAmount () {
     HealthD.text = ""+ cHealth;
 }
function Update () 
{
    // if you press Mouse Button
    if (Input.GetMouseButtonDown(0)){ // if you press Left Mouse Button -> GetMouseButtonDown(0) 
        var hit: RaycastHit;
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition); // it sends a ray from Camera.main
        if (Physics.Raycast(ray, hit)){ // if it hits something 
        	if (hit.collider.gameObject.tag == "beep"){        
        		cHealth += -10;
         		HealthD.text = ""+ cHealth;
         		if (cHealth <= 0){
         		    DestroyObject(gameObject);	
         		}
     		}
 		}
    }

but this ended up destroying the first person controller rather than the enemy. Could anyone tell me what is wrong?

Well I am guessing that you have put this one you first person controller, if so you need to separate scripts one for the enemy, and one for the controller.
The first script would be like this:

 function Start() 
        {
    
        }
        function Update ()
        {
        if (Input.GetMouseButtonDown(0)){
        var hit: RaycastHit;
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition); 
        if (Physics.Raycast(ray, hit)){
        if (hit.collider.CompareTag("Beep")){
        hit.collider.gameObject.SendMessage("Damage");
       }
      }
     }
    }

Second script,(Enemy health), would be like this:

private var Health = 100;

function Start(){

}
function Update(){
if(Health <= 0){
Destroy(gameObject);
}
}
function Damage(){
Health -= 10;
}

You could add the function that shows the health at the end.

This method shoots out a ray sees if it hits an object with the tag beep and if does sends a message Damage which the enemy picks up, then it minuses 10 health, then finally the enemy checks if it has any health left if not it destroys itself.