If it doesn’t even print anything then the PlayerAdded function is not working
Try this instead:
local dataStore = game:GetService("DataStoreService"):GetDataStore("SaveData")
local function PlayerAdded(plr)
wait()
local plrid = "id_"..plr.UserId
local save1 = plr.leaderstats.Coins
local save2 = plr.leaderstats.Gems
local save3 = plr.leaderstats.Wins
local save4 = plr.leaderstats.XP
local GetSaved = dataStore:GetAsync(plrid)
if GetSaved then
save1.Value = GetSaved[1]
print("Coins")
save2.Value = GetSaved[2]
print("Gems")
save3.Value = GetSaved[3]
print("Wins")
save4.Value = GetSaved[4]
print("XP")
else
local NumberForSaving = {save1.Value, save2.Value, save3.Value, save4.Value}
dataStore:GetAsync(plrid,NumberForSaving)
end
end
game.Players.PlayerAdded:Connect(PlayerAdded)
for _, player in ipairs(game.Players:GetPlayers()) do
PlayerAdded(player)
end
game:BindToClose(function()
task.wait(3)
for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
dataStore:SetAsync("id_"..plr.UserId, {plr.leaderstats.Coins.Value, plr.leaderstats.Gems.Value, plr.leaderstats.Wins.Value, plr.leaderstats.XP.Value})
end
end)
I have had this issue to, however it isn’t really a problem.
What I found was that my script was working, but it didn’t save the coins when i gave them to myself via commands.
What I mean by that is, when I manually changed my value in the command console or in the leaderstats folder while playing, it wouldn’t save.
Try putting a part into the workspace that, when touched, gives you money, and see if that works instead.
Post edit: Sorry, did not see your previous response with the round system, i thought you were changing it with commands. Make sure the round system gives you coins on a SERVER script. I will look into this further…
Your issue can be fixed but will bring more issues to your game if you use setasync
First of all, a player may leave inmediately when he joins making it possible for the setasync to load faster, plus, you don’t have any session locking since you could leave and join back and the previous setasync may not have loaded yet
You can check the documentation or some videos linked there. I highly suggest you to transition to this module and almost always use it. To prevent further headaches in your scripting life