trouble locating position

what i am attempting here is to spawn a gameobject, that is working. I then get the transform from it i then want to measure the distance between my game object the script is attached to and the Instantiated game object. what i am getting is a set position from somewhere. the second game object is not returning its position. here is the code i have so far.where am i going wrong getting the position from both gameObjects so i can measure distance.

var targetPos : GameObject;
var tarPos : Transform;

function Start () {

var selectedCord : Vector3 = Vector3 (Random.Range(253.0, 312.0), 0 , Random.Range(100.00, 153.00));
Instantiate(targetPos, selectedCord, Quaternion.identity);


function Update () {

tarPos = targetPos.GetComponent(Transform);



function PickCords(){

	var dist =  Vector3.Distance(tarPos.position, transform.position);


The Instantiate method takes a GameObject, clones it, and returns the clone. So you have to assign the return value to something if you want a link to the object you just created. What you need is to follow the examples from the documentation:

In other words,

var newObj : GameObject;
newObj = Instantiate(targetPos, ...);

BTW: calling a GameObject targetPos is very confusing - it’s not a position, it’s a GameObject.