[Solved]Player Prefs stops working at double digits?

so basicly using playerprefs to keep track of high scores however once it gets passed 9 and moves onto 2 digit numbers it doesn’t save a number even tho the varible is still updated

any advice or help on why it would be doing this is appreciated

code for reference

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class Score_Script : MonoBehaviour {

    GameObject myTextgameObject; // gameObject in Hierarchy
    Text ourComponent;           // Our refference to text component
    int Scorecount = 0;
    double slowcount = 0;
    public bool Alive;
    public static int highscore = 0;
    static GameObject hiscoreobject;
    Text hiscorecomponent;
   // GameObject isdead;
    // Use this for initialization
    void Start() {
        highscore = PlayerPrefs.GetInt ("highestscore");
        myTextgameObject = GameObject.Find("Score_Text");
        ourComponent = myTextgameObject.GetComponent<Text>();

        hiscoreobject = GameObject.Find("HiScore_Text");
        hiscorecomponent = hiscoreobject.GetComponent<Text>();

        hiscorecomponent.text = "Highscore " + highscore.ToString();
     //   isdead = GameObject.Find("Player");


    }

    // Update is called once per frame
    void Update() {


        if (GameObject.Find("Player") != null) {
           
            slowcount = slowcount + .1;

            if (slowcount > 6)
            {
                Scorecount++;
                slowcount = 0;

            }
            ourComponent.text = Scorecount.ToString();
        }
        else
        {
               
            //    if (Scorecount > highscore) {
               
                   

                    highscore = Scorecount;


                   
                    PlayerPrefs.SetInt ("highestscore", highscore);
                    print (PlayerPrefs.GetInt ("highestscore"));
            hiscorecomponent.text = "Highscore " + highscore.ToString();
              
            //    }

            }
            }
     



}

Please refer to this page for how you can post code nicely on the forums: Using code tags properly

Does the print (to console) method also print the wrong number? Just checking that it’s not an issue with the size of the UI text element.
There should be no reason you can’t save 2 digit numbers.

1 Like

@methos5k it prints to console just fine however it wont display the double digit numbers for the hiscore where the scorecount still does display the score in double digits

also code post was updated with the format u provided

@methos5k I worked out the problem it was an issue with the size of the ui text element as you suggested thanks for the help

Cool, glad you got it worked out. :slight_smile: