Cancel player movement

Hey hey! So I took the click to move script off the Wiki and made it so while the mouse is held down it will continue to follow the mouse, however what I want to do is make it immediately stop moving after the mouse button is released. I tried using a while but Unity crashes from it. What would be the proper way to go about this?

    // Click To Move script
// Moves the object towards the mouse position on left mouse click

var smooth:int; // Determines how quickly object moves towards position
var HeldDown : boolean = false;
private var targetPosition:Vector3;

function Update () {
         var playerPlane = new Plane(Vector3.up, transform.position);
         var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         var hitdist = 0.0;
         if (playerPlane.Raycast (ray, hitdist)) {
            var targetPoint = ray.GetPoint(hitdist);
            targetPosition = ray.GetPoint(hitdist);
            var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
            transform.rotation = targetRotation;
    transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);

You’ll need to add something like

if (Input.GetMouseButtonUp) {
  canmove = false;
//  targetPosition = transform.position;

and change your transform.position line into

if (canmove) {
    transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);

canmove is a bool that you declare on top of your code.
Possibly not the best solution, but it should put you on the right track.