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

How come kills wont be added but Deaths will?

Asked by 3 years ago
Edited 3 years ago

I have a leaderboard that has Kills and Deaths and for some reason, it only adds to the deaths when a player dies but it doesn't add to the killer's kills. Why isn't it working?

player.CharacterAdded:Connect(function(Character)
        local Humanoid = Character:FindFirstChild("Humanoid")

        Humanoid.Died:Connect(function(Died)
            Deaths.Value += 1
            local Tag = Humanoid:FindFirstChild("creator")
            local Killer = Tag.Value
            if Tag and Killer then -- wont work
                Killer.LeaderStats:FindFirstChild("Kills").Value += 1
            end
        end)
    end)

1 answer

Log in to vote
0
Answered by
Neatwyy 123
3 years ago
Edited 3 years ago

You should loop through all the players' characters to see if they're a killer or not.

player.CharacterAdded:Connect(function(Character)
    local Humanoid = Character:FindFirstChild("Humanoid")

    Humanoid.Died:Connect(function(Died)
        Deaths.Value += 1

        for i, v in pairs(game.Players:GetPlayers()) do -- loops through all the players
            local Tag = v.Character.Humanoid:FindFirstChild("creator")

            if Tag then
                local Killer = Tag.Value

                if Killer then
                    Killer.LeaderStats:FindFirstChild("Kills").Value += 1
                    break
                end
            end

        end

    end)
end)
Ad

Answer this question