RayCast not working properly

I have a ray cast script. When I press control it makes a ray in the editor. I have the ray go through the monster and doesn’t always lowers a monsters health. Only sometimes it does. Also if I get to close to the monster and touch him, his health goes down rapidly and I haven’t even fired a ray. What did I do wrong? Here is my code.

    var distance : float = 30;

function Update () 
{
	
	if(Input.GetButton("Fire1")){
		
	var dir = transform.TransformDirection(Vector3.forward);
	var hit : RaycastHit;
	
	
	Debug.DrawRay(transform.position, dir * distance, Color.blue);
	
	print("You fired a ray");
	}
	

if(Physics.Raycast(transform.position, dir, hit, distance))
	{
		if(hit.collider.gameObject.tag == "Monster")
		{
			health.Health -= 5;
		
		print("You Hit Him");
		}
	 } 

}

First of all. You only have DEBUG.DrawRay in your FIRE event. The way you have it set up now, you are fireing EVERY FRAME. So move your Physics.Raycast code (that is what really is doing the shooting) inside your “Fire event” brackets.

EDIT;

var distance : float = 30;

function Update () 
{

    if(Input.GetButton("Fire1")){

      var dir = transform.TransformDirection(Vector3.forward);
      dir.Normalize();
      var hit : RaycastHit;


      Debug.DrawRay(transform.position, dir * distance, Color.blue);

      print("You fired a ray");

      if(Physics.Raycast(transform.position, dir, hit, distance))
      {
         if(hit.collider.gameObject.tag == "Monster")
         {
           health.Health -= 5;
 
           print("You Hit Him");
         }
       } 
    }
}

EDIT2: Maybe your Debug ray was 2 long because you didnt normalize direction.
EDIT3: Fixed code bug.