Object reference not set to an instance of an object

Hi I’m quite new to coding and am trying to learn javascript, however I’m stuck on a particular issue:/

NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs)
Aidamage.Update () (at Assets/Scripts/Part 2 - Survival GUI/Aidamage.js:19)

Basically my game is a survival game, and I’m trying to allow my character to damage my npc, here is my code:

var health = 20;
var newhealth;
var damage = 5;
var wait_time = 2;
var lock = 0;
var rayLength = 10;

function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);

if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
playerAnim = GameObject.Find(“FPSArms_Axe@Idle”).GetComponent(PlayerControl);

if(hit.collider.gameObject.tag == “enemy” & Input.GetButtonDown(“Fire1”) & playerAnim.canSwing == true) {
newhealth -= 5;
}
if(health == 0){
Destroy(GameObject);
}
}
}

Would anybody be able to help?

NullReferenceException errors mean that an object is being used that doesn’t have a value (i.e. it’s null).

Are you sure GameObject.Find(“FPSArms_Axe@Idle”) returns a value object before you use GetComponent(PlayerControl) on it? Try this:

playerAnim = GameObject.Find("FPSArms_Axe@Idle");
Debug.Log("Is this value null: " + playerAnim);

And see what pops up in the console. If it’s null, then you need to fix the name of your object.

same issue, Its annoying as it doesnt say what is null.

the error has a line number on it, something on that line is null. If you have laid out you code nicely it really shouldn’t be more than a couple of options.