How do I get my endless runner high score,How do I make high score for an endless runner

Hello, the script works as far as keeping up with the score, however it doesn’t save the high score as predicted. I would appreciate the help and Thank in advance.

public Transform player;
    public Text scoreText;
    public Text highScoreText;
    private float score;
    private float highScore;

    

    void Start()
    {
        highScoreText.text = highScore.ToString();
        highScore = PlayerPrefs.GetFloat("HighScore", highScore);
    }

    void Update()
    {
        scoreText.text = score.ToString("0");
        score = player.position.z;

        if (score > highScore) {
            PlayerPrefs.SetFloat("HighScore", highScore);
            highScore = score;
        }

    }

,This scripts works but however, it doesn’t save the highScore on the UI. I would appreciate the help and Thank you in advance.`

public Transform player;
public Text scoreText;
public Text highScoreText;
private float score;
private float highScore;



void Start()
{
    highScoreText.text = highScore.ToString();
    highScore = PlayerPrefs.GetFloat("HighScore", highScore);
}

void Update()
{
    scoreText.text = score.ToString("0");
    score = player.position.z;

    if (score > highScore) {
        PlayerPrefs.SetFloat("HighScore", highScore);
        highScore = score;
    }

}`

You are not changing it in the ui. What you do is set the high score to the text, then read the high score in the Start().

What you want to do is read the high score first, then assign it to the text.

 void Start()
 {
     highScore = PlayerPrefs.GetFloat("HighScore", highScore);
     highScoreText.text = highScore.ToString();
 }