Score doesn't start with 0 at the begging of the game

So I save data from a scene to another but when I start again the game I still have the score that I gain after playing . I am at the first scene and my score is 4 instead of 0 . How can I get my score at new game = 0 ? here is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ScorePanelUpdater : MonoBehaviour
{
    //Start is called before the first frame update
   
      void Update()
      {
          GameObject go = GameObject.Find("Score");
          if(go == null)
          {
              Debug.LogError("Failed");
              this.enabled = false;
              return;
          }



          Score gs = go.GetComponent<Score>();
      
    GetComponent<Text>().text = " Score: " + gs.GetScore();
    }
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Score : MonoBehaviour
{

    public Text scoreText;
    public int score;
    public Button button;

    // Use this for initialization
    void Start()
    {
        score = PlayerPrefs.GetInt("score", 0);
        Button btn = GetComponent<Button>();
        button.onClick.AddListener(TaskOnClick);
    }


    void Update()
    {
        scoreText.text = "Score: " + score;
    }

    void OnDestroy()
    {
        PlayerPrefs.SetInt("score", score);


    }

    public void AddScore(int s)
    {
        score += s;

    }
    public int GetScore()
    {
        return score;
    }


    // Update is called once per frame

    void TaskOnClick()
    {
       
       
            score++;
       
    }
}

Use PlayerPrefs.Save() next to every PlayerPrefs.Set…

It seems like if you want to have your score stick around from scene to scene, you could make the Score script a singleton or use DontDestroyOnLoad. Then when a game ends, instead of it destroying it, just have a method that resets the score back to zero - like a reset method.


I would only use PlayerPrefs to store a Highscore, not just a normal score.