Hello there, I have made a leaderboard script and the datastore script. There’s a problem. The datastore works only on the Falls value, but not on the Cash value. Here are both scripts
Leaderboard script
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Falls = Instance.new("IntValue")
Falls.Name = "Falls"
Falls.Value = 0
Falls.Parent = leaderstats
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = 0
Cash.Parent = leaderstats
end)
DataStore script
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userId
local save1 = plr.leaderstats.Falls
local save2 = plr.leaderstats.Cash
local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
else
local NumberForSaving = {save1.Value, save2.Value}
ds:GetAsync(plrkey, NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Falls.Value}, {plr.leaderstats.Cash.Value})
end)
Help would be appriciated, there are no errors. I’m really confused.