Is my script not saving or not loading?
Hi. I am trying to make the currency in my game save with Data Store. It currently saves with Data Persistence, but as I am creating more features throughout my game's universe, I will need it to be in Data Store.
I have tried many different things, but nothing has worked.
Load:
1 | ds = game:GetService( "DataStoreService" ):GetDataStore( "Money" ) |
4 | game.Players.PlayerAdded:connect( function (player) |
5 | local value = player.Money |
7 | value.Value = ds:GetAsync(player.userId) |
Save:
1 | ds = game:GetService( "DataStoreService" ):GetDataStore( "Money" ) |
4 | game.Players.PlayerRemoving:connect( function (player) |
5 | local value = player.Money |
7 | ds:SetAsync(player.userId, value.Value) |
My game is set up so when you join an IntValue is created directly inside of game.Players.LocalPlayer. Whenever you purchase something, a certain number is subtracted from that value. A LocalScript in the PlayerGui continuously checks for updates to the Value, and when it does it changes the text of a TextLabel which shows how much money you have.
I get no errors in my output when I start the game. Everything works fine except for one of those two scripts. Both of the codes are run in a Script (not LocalScript, etc.) and they are being tested in online mode. Thanks for your time!