Why this script is not working?

Hi,i have script,i wanted to make it that i can only press “n” button from a certain distance,but its not working,why,please check it out and help me ;(

        var myDistance: float = 20;
        var cube : GameObject;
        var jointExist : boolean;
       
        function OnCollisionEnter(c : Collision) {
     
        if(!jointExist){
     
          var joint = gameObject.AddComponent(FixedJoint);
     
          joint.connectedBody = c.rigidbody;
     
          jointExist = true;
     
       }
     
    }
       
        function Update(){
            if(Input.GetKeyDown(KeyCode.N)){
                if(Vector3.Distance(transform.position, cube.transform.position) < myDistance){
                    if(!jointExist){
                        var joint = gameObject.GetComponent(FixedJoint);
                        Destroy(joint);
                        jointExist = false;
                    }
                }
            }
         
        }

I’m not 100% sure what this script is attempting to do, but I imagine that in Update, the 3rd if statement should read:

if (jointExist == true)

rather than checking if it’s false.