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

Kills/Deaths Auto save Script? [closed]

Asked by 6 years ago

I Have This Script here

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)

There you Go

Closed as Non-Descriptive by RaverKiller and Goulstem

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?