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

Help need my script for a wokring kills and deaths leaderstats does not work?

Asked by 4 years ago

The code I made, the deaths works but not kills. Can somebody help?

game.Players.PlayerAdded:Connect(function(plr) local stats = Instance.new("Folder") stats.Name = "leaderstats" stats.Parent = plr

local kills = Instance.new("IntValue")
kills.Name = "KOs" 
kills.Parent = stats

local deaths = Instance.new("IntValue")
deaths.Name = "WOs" 
deaths.Parent = stats

plr.CharacterAdded:Connect(function(char)
    local humanoid
    repeat
        humanoid = char:FindFirstChild("Humanoid")
        wait()

    until humanoid
    humanoid.Died:Connect(function(char)
        deaths.Value = deaths.Value + 1

        local tag = humanoid:FindFirstChild("creator")
        if tag
        then
            local killer = tag.Value
            if killer then


                killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
                end
        end
    end)
end)

end)

0
Is this supposed to be a regular leaderstats script or is it a custom leaderstats? Jakob_Cashy 79 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
local currencyName = "DR and DP" 
local DataStore = game:GetService("DataStoreService"):GetDataStore("UC")

game.Players.PlayerAdded:Connect(function(player)

    local stats = Instance.new("Folder")
        stats.Name = "leaderstats"
        stats.Parent = player

        local DP = Instance.new("IntValue")
        DP.Name = "Points"
        DP.Parent = stats

        local DR = Instance.new("IntValue")
        DR.Name = "Rolls"
        DR.Parent = stats

    local ID = currencyName.."-"..player.UserId
    local savedata = nil

    pcall(function()
        savedData = DataStore:GetAsync(ID)
    end)

    if savedData ~= nil then
        DP.Value = savedData
        DR.Value = savedData
        print("Data loaded")
    else
        DP.Value = 0 
        DR.Value = 0
        print("New player to the game")
    end


end)

game.Players.PlayerRemoving:Connect(function(player)
    local ID = currencyName.." - "..player.UserId
    DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)

game:BindToClose(function()


    for i, player in pairs(game.Players:GetPlayers()) do
        if player then
            player:Kick("This Game is Shutting down for saving data and adding updates plz rejoin :D ")
        end
    end

    wait(5)

end)

This code does not save, but it should, anyways, it does make a leaderstats appear with two variables, just change it to your stuff and it should work.

0
ayyyyy Jakob_Cashy 79 — 4y
Ad

Answer this question