Animation for weapon plays on game start instead of when i attack

so i made an animation for a melee weapon called mace which is made up of two parts in an empty game object child which is a child of my main camera on my first person controller, on game start my mace starts swinging constantly, the animation is set as a “once” not “looping” which is making me think it’s calling for the animation to play every frame instead of when i press “fire1” - mouse 0, the script that calls the animation is attached to the main camera.

here:

var Damage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheMace : Transform;
 
function Update ()
{
    if (Input.GetButtonDown("Fire1"))
    {
    	TheMace.animation.Play("MaceSwing");
        var Hit : RaycastHit;
 
        if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Hit))
        {
            Distance = Hit.distance;
            if (Distance < MaxDistance)
            {
                Hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
            }
        }
    }
}

i even created a variable of type transform then attached the mace to it and it woulden’t work.

my attack function has also been messed up by this and here is the error message:

MissingComponentException: There is no ‘Animation’ attached to the “Mace” game object, but a script is trying to access it.
You probably need to add a Animation to the game object “Mace”. Or your script needs to check if the component is attached before using it.
UnityEngine.Animation.Play (System.String animation) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/Animations.cs:569)
MelleSystem.Update () (at Assets/scripts/MelleSystem.js:10)

this might help with solving this problem.

can anyone help?

In the inspector there is an option to play animation on start, is this selected?

I don’t suppose in the animator window you have this MaceSwing animation as the default animation?