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:
ds = game:GetService("DataStoreService"):GetDataStore("Money")
game.Players.PlayerAdded:connect(function(player)
local value = player.Money
wait(1)
value.Value = ds:GetAsync(player.userId)
end)
Save:
ds = game:GetService("DataStoreService"):GetDataStore("Money")
game.Players.PlayerRemoving:connect(function(player)
local value = player.Money
wait(1)
ds:SetAsync(player.userId, value.Value)
end)
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!
