Ok, I was the first person to join the game and now I'm the only person with a value in the leaderboard, the issue is when another person joins it errors saying "Argument Missing or nil" on line 12 of the following script and I have no idea why. Anyone know why?
DataStore = game:GetService("DataStoreService"):GetDataStore("Values") game.Players.PlayerAdded:connect(function(plr) local val = 0 local save = "plr-"..plr.userId local savedVals = DataStore:GetAsync(save) if savedVals then val = savedVals else val = 0 DataStore:SetAsync(save) end local stat = Instance.new("IntValue", plr) stat.Name = "leaderstats" local cred = Instance.new("IntValue", stat) cred.Value = val cred.Name = "Credits" end) game.Players.PlayerRemoving:connect(function(plr) local val = plr.leaderstats.Credits.Value local save = "plr-"..plr.userId DataStore:SetAsync(save) end)
You are forgetting to save your value on line 12
and line 26
DataStore = game:GetService("DataStoreService"):GetDataStore("Values") game.Players.PlayerAdded:connect(function(plr) local val = 0 local save = "plr-"..plr.userId local savedVals = DataStore:GetAsync(save) if savedVals then val = savedVals else val = 0 DataStore:SetAsync(save,val) end local stat = Instance.new("IntValue", plr) stat.Name = "leaderstats" local cred = Instance.new("IntValue", stat) cred.Value = val cred.Name = "Credits" end) game.Players.PlayerRemoving:connect(function(plr) local val = plr.leaderstats.Credits.Value local save = "plr-"..plr.userId DataStore:SetAsync(save,val) end)
Hope this helps