[HELP] NPC script problem

hello…

I would like to ask a few question. I try to make a NPC interaction with my Player.

this is my script:

var target : Transform;
var range = 10.0;



function Start ()
{
	
	animation.wrapMode = WrapMode.Loop;
	
}


function Awake()
{
     target = GameObject.FindWithTag ("Player").transform;
}

function Update () 
{
     if(target  CanWaveTarget())
	 {
		
		 
	     var targetRotation = Quaternion.LookRotation(target.position - transform.position, Vector3.up);
		 transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 4.0);
		 
	 }
	 
	 
}

function CanWaveTarget()
{
     if(Vector3.Distance(transform.position, target.position) > range)
	 {
	     animation.CrossFade("idle");
	     print("out of range");
		 return false;
	 }
	 
	 var hit : RaycastHit;
	 
	 if(Physics.Linecast(transform.position, target.position, hit))
	 {
	     print("Item in the way: "+hit.collider.gameObject.name);
		 return false;
	 }
	 else
	 {
	     animation.CrossFade("wave");
	     print("Player detected!");
		 
		 return true;
	 }
	 
	 return true;
}

the problem is this, I would like to make the NPC from idle stat wave at my Player when I come close to the NPC.

the idle animation work fine if my Player is far away and my NPC follow my movement when I come close to the NPC.

But when I come close the NPC did not wave at me.what is wrong with my script.

anyone?