Score storing

I guys, I search for the same problem but I didn’t found something …

I made my first video game (yeaaaah :slight_smile: ) and everything works well until I build an .exe.

I explain, when I build the game and try playing on an other PC, the storing system for my score doesn’t seems to work.
I thought it was because I’m using the free version of Unity and not the professional one ??? (because it works fine on my computer even with the same .exe)

Here is my code in .js :

    #pragma strict

var youwin : GameObject;
var gainPoints:float=0;
var menuScore:GameObject;


function Start () {
 Time.timeScale = 1;
 youwin.GetComponent(GUIText).pixelOffset.x = 4096;
 youwin.GetComponent(GUIText).text = "Score:"+gainPoints;

function Update () {


function applyPoints(points:float){

function AddScore(name : String, score : int){
   var newScore : int;
   var newName : String;
   var oldScore : int;
   var oldName : String;
   var i: int;
   newScore = gainPoints;
   newName = name;


   for( i=0;i<10;i++){

      if(PlayerPrefs.HasKey(i+"HScore") && PlayerPrefs.GetInt(i+"HScore")<newScore){
        // new score is higher than the stored score
        oldScore = PlayerPrefs.GetInt(i+"HScore");
        oldName = PlayerPrefs.GetString(i+"HScoreName");
        newScore = oldScore;
        newName = oldName;

function UpdateHScore(){
 var Score1 : GameObject;
 Score1= GameObject.Find("menu_container/txt_score_1st-score");
 var Score2 : GameObject;
 Score2= GameObject.Find("menu_container/txt_score_2nd-score");
 var Score3 : GameObject;
 Score3= GameObject.Find("menu_container/txt_score_3rd-score");
 var Score4 : GameObject;
 Score4= GameObject.Find("menu_container/txt_score_4th-score");
 var Score5 : GameObject;
 Score5= GameObject.Find("menu_container/txt_score_5th-score");
 var Score6 : GameObject;
 Score6= GameObject.Find("menu_container/txt_score_6th-score");
 var Score7 : GameObject;
 Score7= GameObject.Find("menu_container/txt_score_7th-score");
 var Score8 : GameObject;
 Score8= GameObject.Find("menu_container/txt_score_8th-score");
 var Score9 : GameObject;
 Score9= GameObject.Find("menu_container/txt_score_9th-score");
 var Score10 : GameObject;
 Score10= GameObject.Find("menu_container/txt_score_10th-score");
 var Name1 : GameObject;
 Name1= GameObject.Find("menu_container/txt_score_1st-name");
 var Name2 : GameObject;
 Name2= GameObject.Find("menu_container/txt_score_2nd-name"); 
 var Name3 : GameObject;
 Name3= GameObject.Find("menu_container/txt_score_3rd-name");
 var Name4 : GameObject;
 Name4= GameObject.Find("menu_container/txt_score_4th-name");
 var Name5 : GameObject;
 Name5= GameObject.Find("menu_container/txt_score_5th-name");
 var Name6 : GameObject;
 Name6= GameObject.Find("menu_container/txt_score_6th-name");
 var Name7 : GameObject;
 Name7= GameObject.Find("menu_container/txt_score_7th-name"); 
 var Name8 : GameObject;
 Name8= GameObject.Find("menu_container/txt_score_8th-name");
 var Name9 : GameObject;
 Name9= GameObject.Find("menu_container/txt_score_9th-name");
 var Name10 : GameObject;
 Name10= GameObject.Find("menu_container/txt_score_10th-name");

    Score1.guiText.text = PlayerPrefs.GetInt("0HScore").ToString();
 Name1.guiText.text = PlayerPrefs.GetString("0HScoreName");

    Score2.guiText.text = PlayerPrefs.GetInt("1HScore").ToString();
 Name2.guiText.text = PlayerPrefs.GetString("1HScoreName");

    Score3.guiText.text = PlayerPrefs.GetInt("2HScore").ToString();
 Name3.guiText.text = PlayerPrefs.GetString("2HScoreName");

    Score4.guiText.text = PlayerPrefs.GetInt("3HScore").ToString();
 Name4.guiText.text = PlayerPrefs.GetString("3HScoreName");

    Score5.guiText.text = PlayerPrefs.GetInt("4HScore").ToString();
 Name5.guiText.text = PlayerPrefs.GetString("4HScoreName");

    Score6.guiText.text = PlayerPrefs.GetInt("5HScore").ToString();
 Name6.guiText.text = PlayerPrefs.GetString("5HScoreName");

    Score7.guiText.text = PlayerPrefs.GetInt("6HScore").ToString();
 Name7.guiText.text = PlayerPrefs.GetString("6HScoreName");

    Score8.guiText.text = PlayerPrefs.GetInt("7HScore").ToString();
 Name8.guiText.text = PlayerPrefs.GetString("7HScoreName");

    Score9.guiText.text = PlayerPrefs.GetInt("8HScore").ToString();
 Name9.guiText.text = PlayerPrefs.GetString("8HScoreName");

    Score10.guiText.text = PlayerPrefs.GetInt("9HScore").ToString();
 Name10.guiText.text = PlayerPrefs.GetString("9HScoreName");

Here is the code from where the score values are sent:

#pragma strict

function Start () {


function Update () {


var on : int = 0;
var NameEditArea : String = "Enter your name";

function OnGUI () {

 if (on == 1){
 var go = GameObject.Find("ScoreCount");
 var score : int;
 Time.timeScale = 0;
     // Make a text field that modifies name.
    var centeredStyle ="Label");

    centeredStyle.alignment = TextAnchor.UpperLeft;
     NameEditArea = GUI.TextArea (Rect (Screen.width/2-100, Screen.height/2-25, 200, 50), NameEditArea, 200);
     //name = GUI.TextField (Rect (Screen.width/2-50, Screen.height/2-25, 200, 50), name, centeredStyle);
 if (Input.GetKey ("enter")){
        go.GetComponent(ScoreScript).AddScore(NameEditArea ,score);
 if (GUI.Button(Rect(Screen.width/2+100,Screen.height/2-25,150,50),"Enter")){
 go.GetComponent(ScoreScript).AddScore(NameEditArea ,score);



Does someone knows something about this ???


If you are using floats for your score I recommend using playerPrefs to save. and it will transfer them between machines.

I used them to save and load a players position in my game. This has a working example also.


hope it helps.

Tks a lot Kurotatsu, I’m analysing this and I’ll post something working well !