It says "Null reference exception : Object reference not set to an instance of an object"

The code doesnt have any errors apart from this , But when i play it nothing happens either , what i tyring to do is turn off the Acog mesh for my gun , and turn on the iron sights for my gun . same with the acog on , sights off when i press 1 or 2 heres the code

var attachmentOne : GameObject;
var attachmentTwo : GameObject;

function Update () 
{
  if ( Input.GetButtonDown("Disable1"))
  {
        attachmentOne.Renderer.enabled = false; 
        }
        else
        {
        attachmentTwo.Renderer.enabled = true; 
  }         
  if ( Input.GetButtonDown("Disable2"))
  {
        attachmentTwo.Renderer.enabled = false; 
        }
        else
        {
        attachmentOne.Renderer.enabled = true; 
  }       
            
}

Assuming you assigned attachmentOne and attachmentTwo via the Inspector, you should use small ‘r’:

attachmentOne.renderer.enabled; // for example

That error means that your VARIABLES have not been assigned in the inspector…
and if it has… chances are it HASNT on another object
(chances are another object also has the code attached… maybe accidentally, and you just need to remove the script from that object.)