Hi guys! I have 3 leaderstats that I originally was saving when the player left the game, but if the game crashed it didn't save. So, I am now saving when it changes! Any ideas why this is not saving? Thanks!
local ds = game:GetService("DataStoreService"):GetDataStore("stats") lolz={"Escapes","Coins","Diamonds"} game.Players.PlayerAdded:connect(function(plyr) local a=Instance.new("NumberValue") a.Parent=plyr a.Name="leaderstats" for i=1,#lolz do local stat=Instance.new("NumberValue") stat.Parent=a stat.Value=0 stat.Name=lolz[i] end child=plyr.leaderstats:GetChildren() -- made it global for efficiency for i=1, #child do child[i].Value=ds:GetAsync(plyr.userId..child[i].Name) end for i,v in pairs (child) do v.Changed:connect (function () ds:SetAsync (plyr.userId,v.Value) end) end end)
You're pulling plyr.userId .. child[i].Name but you are saving it under plyr.userId
Try this:
ds:SetAsync(plyr.userId .. v.Name, v.Value)
on line 20