Object reference not set to an instance of an object?!

HELP! I can’t work out what on earth is going on here! Just so you know, I am trying to spawn two Game Objects randomly at any two of three pre-set spawn locations, while making sure that only one ‘orb’ appears at each.

EDIT: Perhaps I should also note that I am attaching this script to the ‘spawn1’ empty Game Object.

// Currently works, however more than one GameObject often spawns at a given point.

var spawn : Transform[];
var orbs : GameObject;
var orbCount : int = 0;

function Start () {

	var randomPick : int = Random.Range(1,3);

	if (gameObject.Find('spawn'+randomPick)) {

	InvokeRepeating("spawnOrbs", 1, 1);

function Update () {

	if (orbCount >= 2) {


function spawnOrbs () {

	var randomPick : int = Random.Range(1,2);
	if ("spawn"+[randomPick]) {
	var instance = Instantiate(orbs, gameObject.Find('spawn'+randomPick).position, transform.rotation); // Set to instance of object
	Debug.Log("Orb Spawned!");
	Destroy(gameObject.Find("spawn"+randomPick)); // Destroys spawnPoint when object spawns!
	} else {
	Debug.Log("Spawn point doesn't exist");


It is line “var instance = Instantiate(orbs, gameObject.Find(‘spawn’+randomPick).position, transform.rotation);” that throws up the error. I can’t tell if it has a problem with ‘orbs’ or ‘gameObject.Find(‘spawn’+randomPick)’. I should point out that I have three empty game objects named spawn1, spawn2 and spawn3 in the scene, and have dragged these into the ‘spawn’ variable in the inspector.

This means that an object reference had not been assigned to your orbs variable. Have you rechecked it in the Inspector to see that it hasn’t lost your reference?