Destroy on range command

Ok, so here is my code:

function Update () 

{

transform.Rotate (Vector3 (0, 2, 0));

target = GameObject.FindWithTag("Player");
range = Vector3.Distance(target.transform.position, transform.position);
if (range<5)
{
	Destroy (gameObject);
}

}

and here is the error it produces:

Assets/Player/ammoreplenish/ammospin.js(8,18): BCE0051: Operator ‘<’ cannot be used with a left hand side of type ‘function(int): System.Collections.Generic.IEnumerable’ and a right hand side of type ‘int’.

I don’t understand what it’s having a problem with. How do I fix it?

Hi. You did not define the variable “range” and therefor it did not work.

function Update () 
{
transform.Rotate (Vector3 (0, 2, 0));

target = GameObject.FindWithTag("Player");

var range = Vector3.Distance(target.transform.position, transform.position);
if(range < 5)
{
    Destroy (gameObject);
}
}

Here you go!