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

My autosave script doesn't save stats?

Asked by 7 years ago

This Script doesn't Save

local Use_DB = true

function saveStat(plr,val,key)
    if plr then
        plr:WaitForDataReady()
        plr:SaveNumber(key,val)
    end
end

function loadStat(plr,key,stat)
    if plr then
        plr:WaitForDataReady()
        stat.Value = plr:LoadNumber(key,val)
    end
end

game.Players.PlayerAdded:connect(function(player)
    Stat = Instance.new("IntValue",player)
    Stat.Name = "leaderstats"
    Kills = Instance.new("IntValue",Stat)
    Kills.Name = "Kills"
    Deaths = Instance.new("IntValue",Stat)
    Deaths.Name = "Deaths"
    if Use_DP then
        loadStat(player,"Kills",Kills)
        loadStat(player,"Deaths",Deaths)
    end
    player.CharacterAdded:connect(function(char)
        char.Humanoid.Died:connect(function()
            Deaths.Value = Deaths.Value +1
            if Use_DP then
                saveStat(player,Deaths.Value,"Kills")
            end
            Cre = char.Humanoid:FindFirstChild("creator")
            if Cre then
                if Cre.Value then
                    if Cre.Value ~= player then
                        Cre.Value.leaderstats.Kills.Value = Cre.Value.leaderstats.Kills.Value +1
                    else
                        Kills.Value = Kills.Value -1
                    end
                    if Use_DP then
                        saveStat(Cre.Value,Cre.Value.leaderstats.Kills.Value,"Kills")
                        saveStat(player,Kills.Value,"Kills")
                    end
                end
            end
        end)
    end)
end)

Help Please!

0
SaveNumber, LoadNumber, WaitForDataReady are all deprecated. Corexty 15 — 7y
0
This is using data persistence which is deprecated, you need to convert this to use a data store. User#5423 17 — 7y

Answer this question