Print playerpref to guitext?

Hello, I would like to know how to print a playerpref name to a guitext.

My script that makes the name:

var pos : Rect;
private var Car : GameObject;
private var Perf : GameObject;
var pos2 : Vector3;
var pos3 : Vector3;

function Update () {

Car = gameObject.FindWithTag("Car_Selection");
Perf = gameObject.FindWithTag("CarPerf");

}
function OnGUI () {

    if (GUI.Button (pos, "McAron MP3")) {
	Destroy(Car);
	Destroy(Perf);
	var obj : GameObject = Instantiate (Resources.Load ("MP4_SEL"), pos2, Quaternion.identity);
	var obj2 : GameObject = Instantiate (Resources.Load ("MP3Perf"), pos3, Quaternion.identity);
	PlayerPrefs.SetString("Car Name", "Car2");
    }

}

Script that loads the name:

function Start(){

var CarName : float = (PlayerPrefs.GetString("Car Name"));

guiText.text(CarName.ToString());

}

But I get the errors:

Cannot convert 'String' to 'float'.
It is not possible to invoke an expression of type 'String'.

Any ideas?

Why are you calling GetString() and trying to cast as a float?

function Start() {
     var CarName : String = PlayerPrefs.GetString("Car Name");
     guiText.text = CarName;
}

Hi carking1996

I think that the problem is because in the function Start you are trying to take a String
and put it in a float var you can’t do that. “var CarName : float = (PlayerPrefs.GetString(“Car Name”));”

Try like that:

var CarName = PlayerPrefs.GetString("Car Name");

or

var CarName: string = PlayerPrefs.GetString("Car Name");

Thankyou! It works wonderfully! :smile: