Attaching a Hinge Joint upon colliding with a rigidbody. (419527)

I’m trying to create a script that will attach rigidbodies together via hinge joint based on anything that collides with them that also has the tag of “piece”. I’m having trouble figuring out how to define the hingeJoint.connectedBody to understand it needs to attach itself to what collides with it.

    function OnCollisionEnter(other : Collision){

       if (other.gameObject.tag == "piece") {
			
			gameObject.AddComponent(HingeJoint);
				var otherBody = gameObject.collider;
				hingeJoint.breakForce = 45;
				hingeJoint.breakTorque = 45;
				hingeJoint.connectedBody = otherBody;
			}
	}

When playing the scene with this code attached to my game objects mass Hinge Joints will be placed on each object.

I have decided to switch from a Hinge Joint to a Fixed joint. This script works for the most part. It doesn’t create lots of hinges very well, for instance many parts to a simple cube structure. But would work for a sticky bomb or something.

function OnCollisionEnter(collision: Collision) {
if (collision.rigidbody) {
   var fixedJoint: FixedJoint = gameObject.AddComponent(FixedJoint); 
   fixedJoint.connectedBody = collision.rigidbody;
   fixedJoint.breakForce = 45;
   fixedJoint.breakTorque = 45;
}
Destroy(this);
}

If you have any ideas on how to make this script create Fixed Joints to more than one object it collides with AND not create more joints then are required please feel free to expand and improve on this script.

I tried to use: fixedJoint.connectedBody = collision.rigidbody;
but I got the following error: Assets/connect.js(10,25): BCE0005: Unknown identifier: ‘fixedJoint’.

So I changed fixedJoint to FixedJoint and got this:
Assets/connect.js(10,36): BCE0020: An instance of type ‘UnityEngine.Joint’ is required to access non static member ‘connectedBody’.

any help would be appreciated.