"Object reference not set to an instance of an object" Error

Hi all, I am attempting to create a function, located in the main Camera object, that is called by the player object when something specific happens. The function simply inverts the value of a float in the Camera object by multiplying it against -1.

However, whenever the event happens in the game (the player passing a specific trigger) I am met with the error “Object reference not set to an instance of an object”. I’m using GetComponent to attempt to run the function that is in the camera’s script, but this does not seem to work (in the BeeReverse function below). The next few lines are another GetComponent that is accessing a variable from a different script on the player using the same syntax and it is working fine.

Does anyone have any idea why my attempts to run the function from the camera object are failing?

This is the player’s Code:

var player : GameObject;
player = GameObject.FindWithTag("Player");
var beeCam : Camera;
beeCam = Camera.main;
// These variables are used for the player's health and health bar
var curHP : float=3;
var maxHP : float=3;
var gems : int = 0;
 
function Update(){
	
	if (curHP > maxHP){
		curHP = maxHP;
	}
	
	if (Input.GetKeyDown("escape")){
		Application.LoadLevel(0);
	}
}
	
function ChangeHP(Change:float) {
    // This line will take whatever value is passed to this function and add it to curHP.
    curHP += Change;
     
    // This if statement ensures that we don't go over the max health
    if(curHP>maxHP) {
        curHP=maxHP;
    }
     
    // This if statement is to check if the player has died
    if(curHP<=0) {
        Application.LoadLevel(Application.loadedLevel);  //restarts level
        Debug.Log("Player has died!");
    }
}

function BeeReverse(){
	var camScript : LookAtBee = beeCam.GetComponent(LookAtBee);
	camScript.Flip();   //turns little camera around!
	var moveScript : CharacterControlling = player.GetComponent(CharacterControlling);
	moveScript.fallSpeed = (moveScript.fallSpeed * -1);  
	transform.Rotate(0,180,0);   //turns little bee around!
	
}

This is the camera’s code I’m attempting to access:

var target : Transform;
public var offset : float = 326.05;

@script AddComponentMenu("Camera-Control/Smooth Look At")

function LateUpdate () {
	transform.position.y = (target.position.y) - offset;
}
function Start () {
	// Make the rigid body not change rotation
   	if (rigidbody)
		rigidbody.freezeRotation = true;
}

function Flip(){
	offset = (offset * -1);
}

It should say NullReferenceException before that error. This usually means you’re basically trying to do something with a variable equal to null. You can try using if(camScript) or if(camScript !=null). hope I help.