So i'm trying to change this datastore leaderboard so it will have 2 leaderstats, which is candy and moneys, it works, however, it does not save the moneys and every time you rejoin you will have 0 moneys. I need some help with this please. Thanks =^)
local ds = game:GetService("DataStoreService"):GetDataStore("stats")
local stats = {
"Candy";
}
local moneys = {
"Moneys";
}
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("NumberValue")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
for i=1, #stats do
local stat = Instance.new("NumberValue")
stat.Parent = leaderstats
stat.Value = 0
stat.Name = stats[i]
local stat2 = Instance.new("NumberValue")
stat2.Parent = leaderstats
stat2.Value = 0
stat2.Name = moneys[i]
end
for i, v in pairs(player.leaderstats:GetChildren()) do
v.Value = ds:GetAsync(player.userId..v.Name)
end
end)
game.Players.PlayerRemoving:connect(function(player)
for i, v in pairs(player.leaderstats:GetChildren()) do
v.Value = ds:SetAsync(player.userId..v.Name, v.Value)
end
end)

3 comments
That script is not tested, but pretty sure it works.
It doesn't work, unfortunately. I did a bit of tweaking to fix some errors, where you left out " with leaderstats and such, however, it won't save the moneys value.
on line 15 and 24, I put money instead of moneys