Im getting this error | The left-hand side of an assignment must be a variable, property or indexer

Im new to coding and ive got this error when trying to minus a number from a money variable, ive tried finding a solution but i cant find a fix that relates to my code.

says the error is line 5

 public void BuyMinion1()
 {
    if(PlayerPrefs.GetFloat("Money") >= 500)
    {
        PlayerPrefs.GetFloat("Money") = PlayerPrefs.GetFloat("Money") - 500;

        Minion1Bought = 1;
        PlayerPrefs.SetInt("Minion1Bought", 1);

        Minion1.gameObject.SetActive(true);
        Minion1Desat.gameObject.SetActive(false);
        MHolder1.gameObject.SetActive(true);
        MHolder1Closed.gameObject.SetActive(false);

    }
    
}

As a general point, don’t use PlayerPrefs for your working variables. They are meant to be used when you are quitting a game or if you are saving data, for example a checkpoint. Instead, you should use either fields (variables declared at the Class level, not within methods) or variables that are declared in methods.

The specific error you are getting is on line 5, where the left hand side is saying get a value and the right hand side is saying store a value. If you had said PlayerPrefs.SetFLoat(“Money”), I guess it would have worked OK, since both sides would then have been doing the same thing.

However, going back to my first paragraph, you should probably load all the PlayerPrefs in a Start event and copied them all to variables. Then your code would look like this:

     if(money >= 500)
     {
         Money -= 500;
         Minion1Bought = true;
         ...

I’m assuming that you are familiar with the -= operator. It’s the same as a = a - 500; Also, I have assumed that you will use a boolean for Minion1Bought, which seems more sensible. When you have reached a checkpoint or are ending the game, that is when you would write the values to PlayerPrefs that you want to keep.

Just one thing. Don’t forget that PlayerPrefs are just text and a user could, in theory, find the file and make changes to it. Instant God mode…