NullReferanceException. Please Help

hi got this error and was looking for some help thanks.

NullReferenceException: Object reference not set to an instance of an object
randomCrate.Start () (at Assets/New Folder/randomCrate.js:12)

Here is My Code Below:

var xPos : int;
var zPos : int;
var objectToCreate : Transform;
private var rangeX : int;
private var rangeZ : int;
// Use this for initialization
function Start () {
    xPos = 0;
    zPos = 0;
    rangeX = (GameObject.Find("Ground").transform.localScale.x/2);
    rangeZ = (GameObject.Find("Ground").transform.localScale.z/2);
    for (var i : int = 0;i < 5; i++)
    {
        Instantiate (objectToCreate, Vector3(0, i+0.5, 0), Quaternion.identity);
    }
}
// Update is called once per frame
function Update () {
    if(Input.GetKeyDown("x"))
    {
        xPos = Random.Range(-rangeX,rangeX);
        zPos = Random.Range(-rangeZ,rangeZ);
        Instantiate(objectToCreate, Vector3(xPos,0.25,zPos), Quaternion.identity);     
    }
}

any help is appreciated.
thanks.

Either There’s no object called “Ground” for it to find, or you havent assigned the public variable objectToCreate
Since you didn’t use code tags, or comment the line giving the error, it’s hard to say

1 Like

sorry about the Code tags never knew how to do it.
and because I following a lecture handout some of my names are different and i must of missed that one thanks.

Thanks allot. :smile: