Getting variables from another GameObject

I already tried unsuccessfully to apply this:

http://unity3d.com/support/documentation/ScriptReference/GameObject.GetComponent.html

I always get this error:
NullReferenceException: Object reference not set to an instance of an object

my script:

Script “Goal” on another Object:

var Gg;


function OnTriggerEnter ( coll_1: Collider )
{

Gg++;

}

Script Gui :

var disp_text = "Goal Num: ";

function OnGUI() {

var Goal_obj : Goal = gameObject.GetComponent(Goal);

GUI.Label (Rect(20,10,200,200),disp_text+Goal_obj.Gg);

}

What I want to do is get the value of Gc Gameobject and view it from another function via GUI

Thanks in advance

GameObject.Find(“nameofobject”).GetComponent
if it’s a different gameObject, read the script ref about it

this does not work…

maybe it’s a different procedure from a function GUI

Welcome to the forum, Tony77!

Are you sure the Gg variable is correctly linked in the inspector? Usually this type of error is because nothing is assigned to the variable in question.