NullReferenceException (502585)

If anyone can help me with this, please no, that you have saved my life because I’m about to either A) have a heart attack or B) put a bullet in my brain.

I’m am getting the following message:

NullReferenceException: Object reference not set to an instance of an object
LaserFire.Update () (at Assets/Scripts/LaserFire.js:37)

//Oringal srcipt from tornadow twins

/*
var bullitPrefab : Transform;

function Update ()

{

	if(Input.GetButtonDown("Jump"))
	

	var bullit = Instantiate(bullitPrefab, gameObject.Find("spawnPoint").transform.position,Quaternion.identity);
    
    bullit.rigidbody.AddForce(transform.forward * 200);
			
		


}	
*/

//Copy from orginal: Changed var names from "bullit" to "laserBeamPrefab," and "laserbeam."


var laserBeamPrefab : Transform;

function Update ()

{

	if(Input.GetButtonDown("Jump"))
	

	var laserBeam = Instantiate(laserBeamPrefab, GameObject.Find("spawnPoint").transform.position,Quaternion.identity);
    
    laserBeam.rigidbody.AddForce(Vector3.forward * 200);
    
   
}

“laserBeam” is an instance of a prefab. the “spawnPoint” is a Sphere. Please note: Everything works great! I just cant for the life of me figure out how to get rid of this god damn error message :frowning:

Does your laser beam have a rigidbody attached?

You are missing the braces after your if statement

 if(Input.GetButtonDown("Jump"))
{
    var laserBeam = Instantiate(laserBeamPrefab, GameObject.Find("spawnPoint").transform.position,Quaternion.identity);

    

    laserBeam.rigidbody.AddForce(Vector3.forward * 200);
}

also, you should cache your spawnpoint rather than doing a find everytime.

Yes Glockenbeat , I do have a rigidpody attached. The script does everything its suppose to do, except for giving me an error.

What braces are you talking about JamesLeeNZ? Where can I learn about caching my spawnpoint?

These are braces… { }

you see in the code I posted above, that i have put them in after the if statement surrounding the instaniate and addforce lines.

Thanks for you help buddy! Last night I went through everything fresh: new, code, new, prefabs, new everything, checking everything along along the way. The code is the exact same way as it was before, but this time it works for some reason :confused: