Modify GUI text via javascript

I have this code:

#pragma strict
public var hpPoints : float = 3;
public var CurrentHP : float = 3;


function Start () {
}

function Update () {
var hits;
var maxhits;

hits = GameObject.Find("hitstaken").guiText;
maxhits = GameObject.Find("maxhits").guiText;

hits = CurrentHP.ToString;
maxhits = hpPoints.ToString;

}

function OnCollisionEnter(collision: Collision) {


if (collision.gameObject.tag == "obstacle"){
   CurrentHP -= 1;
}  
print("You have hit an object. " + "You have " + CurrentHP + "/" + hpPoints + " HP points.");

if (CurrentHP <= 0){
  print("You lost!");
 }
}

Everything works except the GUI part. They don’t change how they are suposed to change.
I tried to use “hits.text” but it told me that “text” is not a component of something.
Ideeas ?

You are making “hits” equal to a GuiText, but then you make it equal to a String on line 17. Strings don’t have a “text” variable, only GuiText does.

Change it to:

hits.text = CurrentHP.ToString;
maxhits.text = hpPoints.ToString;

You should also move your "GameObject.Find"s to an Awake or Start function.