store score

I have a problem I can not solve. I want my score to be saved and they are saved to the highest score. These are my 2 scripts .js

//stores score

var trova : Transform;
var miaPos : Transform;
static var nuovoPunteggio;
static var preleva;

function Start () {



}

function Update () {



 var trovaDistanza : float = Vector3.Distance(miaPos.position,trova.position);
 
 
 
if(trovaDistanza <=4.0){
 
 

 
 
 Save(Score.score);
 
 
 
 Application.LoadLevel("GameOver");
 print("Il punteggio di questa partita è :" + Score.score);
 
 }

}


function Save(punteggio:int){

PlayerPrefs.SetInt("punto",Score.score);

//print(punteggio);


}

//read score

#pragma strict

var savedScore:int;
var nuovoPunto : int;


function Start () {

savedScore = PlayerPrefs.GetInt("punto",Score.score); //ultimo punteggio

//print("PUNTEGGIO OTTENUTO: " + savedScore);

if(savedScore > nuovoPunto){

    nuovoPunto = savedScore;


    print("IL PUNTEGGIO PIU' ALTO E': "+ nuovoPunto);



}


}

function Update () {

}

function OnGUI(){


GUI.Label (Rect (10, 10,200, 200), "Punteggio partita: " + savedScore);
GUI.Label (Rect (10, 50,200, 200), "Record punteggio: " + nuovoPunto);





}

You kind of forgot to tell where the problem is.
Do you get any errors?
Or does it just not do what it’s supposed to do?
If so, what is it supposed to do and what does it do instead?

These are all things that you should always tell people if you want efficient help.

What I want is to save the result in a new scene and show the record. I thought that when the enemy comes against me I have to compare the new score with the score saved. Errors from but I do not I get what I want.

Your code would be easier to read for me if you’d stay with english in it :slight_smile:

What about this:

function Save(punteggio:int)
{
  if(punteggio > PlayerPrefs.GetInt("punto"))
  {
    PlayerPrefs.SetInt("punto",punteggio); //why use Score.score if we have punteggio as parameter?
  }
}

Thank you very much :slight_smile: