It’s hard to say exactly where your system is going wrong there because some parts are missing ( is there a save game load somewhere? ), and some of it doesn’t make sense ( why deduct 0 from coins and player coins? ).
But generally speaking the problem will be one of two things:
-
Somehow you are not saving the fact the user has purchased the coins
-
You are saving this fact, but elsewhere in your code you are updating the save game without loading it first, which will wipe anything that was stored there.
Number 2 is a common problem with using a save game variable.