Null Reference Exception for layermask

Ok This is a major edit but I messed with my code and got it to work now I just want to know what the difference is between the two pieces of code because one works one is the code that I had originally had problems with. I just tried both with the same settings and everything and the top one works the bottom one gives me the nre(Null Reference Exception):

WORKS:

var layermask : LayerMask;
var target : Transform;
var height : float;
var distance : float;
var invert : boolean;
private var x: float = 0;
var y : float = 0;

var senX : float;
var senY : float;

var Ymin : float;
var Ymax : float;

function Start ()
{ 

}

function Update () 
{
   x += senX * Input.GetAxis("Mouse X");
   
   if(invert)
   {
      y += senY * -Input.GetAxis("Mouse Y");
   }
   else
   {   
      y += senY * Input.GetAxis("Mouse Y");
   }
   
   if(y > Ymax)
   {
      y = Ymax;
   }
   else if(y < Ymin)
   {
      y = Ymin;
   }
   
   var rotation = Quaternion.Euler(y, x, 0);
   var position = rotation * Vector3(0.0, height, -distance) + target.position;

   transform.rotation = rotation;
   transform.position = position;

   var hit : RaycastHit;
   
   if(Physics.Linecast(target.position, transform.position, hit, layermask))
   {
      var tempDistance = Vector3.Distance(target.position, hit.point);
      position = rotation * Vector3(0.0, height, -tempDistance) + target.position;
      transform.position = position;
      
   }
}

DOES NOT WORK:

var lmask : LayerMask;
var target : Transform;
var height : float;
var distance : float;
var invert : boolean;
private var x: float = 0;
var y : float = 0;

var senX : float;
var senY : float;

var Ymin : float;
var Ymax : float;

function Start ()
{

}

function Update () 
{
   x += senX * Input.GetAxis("Mouse X");

   if(invert)
   {
      y += senY * -Input.GetAxis("Mouse Y");
   }
   else
   {   
      y += senY * Input.GetAxis("Mouse Y");
   }

   if(y > Ymax)
   {
      y = Ymax;
   }
   else if(y < Ymin)
   {
      y = Ymin;
   }

   var rotation = Quaternion.Euler(y, x, 0);
   var position = rotation * Vector3(0.0, height, -distance) + target.position;

   transform.rotation = rotation;
   transform.position = position;

   var hit : RaycastHit;

   if(Physics.Linecast(target.position, transform.position, hit, lmask))
   {
     var tempDistance = Vector3.Distance(target.position, hit.point);
     position = rotation * Vector3(0.0 ,height, -tempDistance) + target.positon;
     transform.position = position;
   }
}

I changed the name of the layer mask to distinguish but I assure you that the top works with the other name and the bottom still never works. So basically what is the difference between the two? It has to do with something inside the if(Physics…) statement but what?

You write “target.positon” in the non working code. (Note the missing ‘i’ in position!)

Do yourself a favour and download a ‘diff’ tool, like WinMerge. With that you’ll be able to easily compare two versions of a file to see what has changed.