Why is PlayerPrefs not Working?

So, playerprefs is giving me errors and it is not saving the game data. Im making an incremental game.
Here is the script:

Here are the errors that im getting:

  1. Assets/Scripts/MoneyClickScriptReal.cs(28,29): error CS1502: The best overloaded method match for `UnityEngine.PlayerPrefs.SetInt(string, int)’ has some invalid arguments

  2. Assets/Scripts/MoneyClickScriptReal.cs(28,29): error CS1503: Argument #2' cannot convert float’ expression to type `int’

PLEASE HELP THANKS!!

Ah, it’s because your money variable is a float, while the key you are using to store it in is a int

You have 3 options

  1. Store money as a float instead of an integer in PlayerPrefs: Now, if in you game you can actually have decimal amounts of money eg. 5.75, then you should really go with this, essentially all you need to do is change your save and load code to

    private void save(){
    PlayerPrefs.SetFloat(“Money”,money);
    }

    private void load(){
    PlayerPrefs.GetFloat(“Money”,0f);
    }
    Essentially what you are doing is changing SetInt() and GetInt() to SetFloat() and GetFloat()

  2. Changing your money variable to an integer

  3. Parsing money to an integer before or while storing it in player prefs

Hope that helps, I would go with 1 myself :slight_smile: