Raycast not ignoring layers?

I made a damage system so when an enemy collides with the raycast and you click it damages the enemy. but every time I put my sword on the player the damage system stops working and I tried to make the raycast ignore the sword but it won’t work, pls help.

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyChecker : MonoBehaviour
{
[SerializeField] private float range;
public LayerMask sword;
public GameObject enemy;
private bool canSlash;

RaycastHit hit;

void FixedUpdate()
{
    Vector3 fwd = transform.TransformDirection(Vector3.forward);
    Vector3 back = transform.TransformDirection(Vector3.back);
    Vector3 dwn = transform.TransformDirection(Vector3.down);
    Vector3 up = transform.TransformDirection(Vector3.up);
    Debug.DrawRay(transform.position, fwd * range, Color.green);

    if (Physics.Raycast(transform.position, fwd,out hit, range -sword)&&hit.transform.tag == "Enemy")
    {
        if (Input.GetMouseButtonDown(0))
        {
            enemy.GetComponent<EnemyHealth>().TakeEDamage(5);
        }

        print("ObjectLocked");

    }

`

Try this

Void fixedupdate ()
{
        RaycastHit hit;
 
    If (input. GetKeyDown (Keycode. Which button you want ))
    {
          if(Physics.Raycast(transform.position, transform.Forward , out hit,  your range, player layer ))
        {
             //Do what you want 
        }
    }
}

On your sword, go to the Inspector tab. From there, go on the layers dropdown, and select the layer, “Ignore Raycast”. This will make the Raycast ignore the sword. Hope this helps!