I have been working on a game that uses in-game currency. I just made a datastore for the game to save the player's currency and work, but when I test it out (In-Studio and on Regular ROBLOX) it doesn't work. And yes, I do have Enable Studio Access to API Services turned on.
Here is my script:
local ds = game:GetService("DataStoreService"):GetDataStore("CoinsSave")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local key = "user_"..plr.UserId
local savevalue = plr.leaderstats.Coins
local savevalue2 = plr.leaderstats.Level
local getSaved = ds:GetAsync(key)
if getSaved then
savevalue.Value = getSaved[1]
savevalue2.Value = getSaved[2]
else
local NumbersForSaving = {savevalue.Value, savevalue2.Value}
ds:GetAsync(key, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
ds:SetAsync("id_"..player.UserId, {player.leaderstats.Coins.Value, player.leaderstats.Level.Value})
end)
Any Help?

5 comments
whats the error ur getting?
I don't get any errors. It just does not save.
It may be because when you set async you do "id_" player Userid, instead of "user_" player Userid, like how you have when the player joins
Okay thanks. I'll try to replace the "id" to "user".
I just replaced the "id" to "user" and it worked! Thank you so much! I have been trying to find out how to fix this problem for a very long time.