My Script Randomly Stopped Working

I’m not sure how this happened, but my script randomly stopped working. It’s supposed to let you break some wood off a door when you get to a certain distance, but no matter how much I increase the distance value it only lets me open it when I’m right in front of it. If anyone can help me fix this I would be really grateful.

Here’s The Script:

public float TheDistance;
public GameObject ActionDisplay;
public GameObject Wood;
public AudioSource Crack;
public GameObject Trigger;
public GameObject Trigger2;

void Update()
{
    TheDistance = PlayerCasting.DistanceFromTarget;
}

void OnMouseOver()
{
    if (TheDistance <= 4f)
    {
        ActionDisplay.SetActive(true);
    }
    if (Input.GetButtonDown("Action"))
    {
        if (TheDistance <= 4f)
        {
            ActionDisplay.SetActive(false);
            Wood.SetActive(false);
            Crack.Play();
            Trigger2.SetActive(true);
            Trigger.SetActive(false);
        }
    }
}

void OnMouseExit()
{
    ActionDisplay.SetActive(false);
}

It is something related to your “TheDistance” variable might be not written how it’s intended to be, try using Vector3.distance(target transform, player transform) <= 4 instead

I somehow fixed it, but I don’t know how. I noticed when I moved the trigger that broke the boards forward a few feet it started working again. Then when I moved it back, it broke. So I moved the trigger, the building, and everything else it was attached to forward and it worked again. If anyone has any idea as to why this worked, please let me know.