-- Function that handles player death and removes one life from the Lives leaderstat
local function onPlayerDead(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local lives = leaderstats:FindFirstChild("Lives")
if lives and lives.Value > 0 then
lives.Value = lives.Value - 1
if lives.Value <= 0 then
player:Kick("You have run out of lives.")
end
end
end
end
-- Function that connects the onPlayerDead function to player deaths
local function onPlayerEntered(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
onPlayerDead(player)
end)
end)
end
game.Players.PlayerAdded:Connect(onPlayerEntered)
this was supposed to make me lose 1 life when i die ut i lost 2