NullReference from External Script

Hi all, I’ve been trying every solution I can find for this but not sure whats going on.

I have a script attached to a chest collider trigger that detects the person entering the collider. That script should access my GUI script and change a boolean variable (chestGUI) from false to true.

+++ Chest Collider Script +++

	//External Access
	var playerGUI : MainGUI;
	playerGUI = GetComponent(MainGUI);
    
	function OnTriggerEnter(other : Collider) 
	{
    	if(this.gameObject.name == "ChestTrigger") // if the object this script is attached to is a chest trigger
    	{
    		// If external MainGUI variable is false (Throwing null reference exception)
    		if(playerGUI.chestGUI == false) 
    		{
    			// Change it to true
    			playerGUI.chestGUI = true;
    		}
    	}
    }

+++ MainGUI Script +++

var chestGUI : boolean = false;

function OnGUI () {
	if(chestGUI)
	{
		GUI.Box (Rect (80,80,70,50), "Chest contents listed here");
	}
	
}

+++ Error +++

 NullReferenceException: Object reference not set to an instance of an object objTrigger.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Collisions/objTrigger.js:12)

I appreciate anyone’s help. Thanks.

Did you try :

if(this.gameObject.name == "ChestTrigger") // if the object this script is attached to is a chest trigger
{
  if(playerGUI == null) {
    Debug.Log("playerGUI is null");
  }
}

Because, I think that GetComponent() didn’t found the MainGUI component here :

playerGUI = GetComponent(MainGUI);

And return a null.
So, are you sure that the gameObject with the ChestColliderScript component has a also the mainGUI component?