Death tracker print

What are you currently working on?

A showcase for you to try out this script. Just tracks your death in the print statement whenever you die!

local deaths = 0

local function handlePlayerDeath(player)
    deaths = deaths + 1
    print(player.Name .. "'s character has died. Total deaths: " .. deaths)
end

local function connectPlayerDeathEvent(player)
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:WaitForChild("Humanoid")

    humanoid.Died:Connect(function()
        handlePlayerDeath(player)
    end)
end

for _, player in ipairs(game.Players:GetPlayers()) do
    connectPlayerDeathEvent(player)
end

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