Accessing variable in another script won't work

So i am trying to acces a variable in another script but it won’t work.

This is the variable i am trying to access

public var Energy : int = 5;

And this is the code in the other script that i am trying to access it with.

var Energy : GameObject;

function startGame () {

Energy = GameObject.Find("Scriptforenergy").GetComponent(Energy);


function OnGUI() {
		if (GUI.Button(Rect(100,100,100,50),"Play")){

Energy is the variable and “Scriptforenergy” is the script i am trying to access the variable in.

Can anyone tell me what is wrong?

You have a variable that is name like a class, you cannot do that. Second your Energy, which should be energy with lower e to differentiate it from the class, is declared as GameObject.

 var energy : Scriptforenergy;

 function Start () {
     energy = GameObject.Find("ObjectName").GetComponent(Scriptforenergy);

Finally, you are using startGame method, are you calling it somewhere or did you mean Start which is automatically called by Unity?