Problem with PlayerPrefs PLS HELP (SOLVED)

Hi, I have problem with PlayerPrefs. I as U see in full code (last code) I use

if (points > highscore)
            {
                PlayerPrefs.SetInt("Highscore", points);
                Debug.Log("New highscore: " + PlayerPrefs.GetInt("HighScore"));
            }

but it just say 0 no matter how many points I will get. Debug.Log is next to the SetInt SO… SetInt write 0 to PlayerPrefs “Highscore”, but why? There are in if with points > highscore that is same to PlayerPrefs “Highscore” because I typed

    void Start()
    {
        highscore = PlayerPrefs.GetInt("HighScore", 0);
    }

by the way it works good when I get 0 points and say nothing about beating highscore

full code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;



public class player : MonoBehaviour {
    public float mvspeed = 600f;
    public int points = 0;
    float movement = 0f;
    public int highscore;

    void Start()
    {
        highscore = PlayerPrefs.GetInt("HighScore", 0);
    }


    void Update () {
        movement = Input.GetAxisRaw("Horizontal");
    }

    private void FixedUpdate()
    {
        transform.RotateAround(Vector3.zero, Vector3.forward, movement * Time.fixedDeltaTime * -mvspeed);
    }

    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        if(otherCollider.name == "HexagonCollider")
        {
            Debug.Log("Score:" + points);
            Debug.Log("Highscore:" + highscore);
            if (points > highscore)
            {
                PlayerPrefs.SetInt("Highscore", points);
                Debug.Log("New highscore: " + PlayerPrefs.GetInt("HighScore"));
            }
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }

        if(otherCollider.name == "PointCollider")
        {
            points += 1;
        }
    }
}

Is it case sensitive? You’ve got “Highscore” and “HighScore”

1 Like

Like Serinx said, your HighScore on 37 is off. You’re fetching one thing that has nothing and storing another never used.

Eh… ok thanks, I am idiot, U R right.
Changed 1 quacking letter and it’s ok.
THANKS YOU

2 Likes