help with DragRigidbody script?

hello all
im rather new to scripting, but i am trying to learn javascript.

my problem is im trying to use the DragRigidbody script in first person but i only want to be able drag objects when i am near to them.

i was trying to add this line

var dist = Vector3.Distance (this.transform.position, GameObject("Rigidbody dragger").transform.position);

so i could track the distance between the dragger, but it just works about 2 times then stops. can i have some help working this out please.

try this, and set distance of object to 5 and distance to 0

var spring = 50.0;
var damper = 5.0;
var drag = 10.0;
var angularDrag = 5.0;
var distance = 0.2;
var DistanceOfObject = 1;
var attachToCenterOfMass = false;
var Enabled : boolean;
private var springJoint : SpringJoint;

function Update ()
{
	
	// Make sure the user pressed the mouse down
	if (!Input.GetMouseButtonDown (0))
		
	return;
	
	var mainCamera = FindCamera();
	
	// We need to actually hit an object
	var hit : RaycastHit;
	if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition),  hit, DistanceOfObject))
	return;
	// We need to hit a rigidbody that is not kinematic
	if (!hit.rigidbody || hit.rigidbody.isKinematic)
	return;
	
	if (!springJoint)
	{
		var go = new GameObject("Rigidbody dragger");
		var body : Rigidbody = go.AddComponent ("Rigidbody") as Rigidbody;
		springJoint = go.AddComponent ("SpringJoint");
		body.isKinematic = true;
	}
	
	springJoint.transform.position = hit.point;
	if (attachToCenterOfMass)
	{
		var anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
		anchor = springJoint.transform.InverseTransformPoint(anchor);
		springJoint.anchor = anchor;
	}
	else
	{
		springJoint.anchor = Vector3.zero;
	}
	
	springJoint.spring = spring;
	springJoint.damper = damper;
	springJoint.maxDistance = distance;
	springJoint.connectedBody = hit.rigidbody;
	
	StartCoroutine ("DragObject", hit.distance);
}

function DragObject (distance : float)
{
	var oldDrag = springJoint.connectedBody.drag;
	var oldAngularDrag = springJoint.connectedBody.angularDrag;
	springJoint.connectedBody.drag = drag;
	springJoint.connectedBody.angularDrag = angularDrag;
	var mainCamera = FindCamera();
	while (Input.GetMouseButton (0))
	{
		var ray = mainCamera.ScreenPointToRay (Input.mousePosition);
		springJoint.transform.position = ray.GetPoint(distance);
		yield;
	}
	if (springJoint.connectedBody)
	{
		springJoint.connectedBody.drag = oldDrag;
		springJoint.connectedBody.angularDrag = oldAngularDrag *2;
		springJoint.connectedBody = null;
	}
}

function FindCamera ()
{
	if (camera)
	return camera;
	else
	return Camera.main;
}

Thank you very much. I hope to try it out when I get back on my computer.

the script works very well thank you very much i will study the script for what youve done and hope i wont need help in the future.