Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Leaderstats not saving?

Asked by 8 years ago

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)

1 answer

Log in to vote
1
Answered by 8 years ago

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

Ad

Answer this question