Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Get the Players service
- local Players = game:GetService("Players")
- -- Function to handle player deaths
- local function onCharacterAdded(character)
- local humanoid = character:WaitForChild("Humanoid")
- -- Listen for humanoid death event
- humanoid.Died:Connect(function()
- -- Kick the player when they die
- local player = Players:GetPlayerFromCharacter(character)
- player:Kick("You died!")
- end)
- end
- -- Listen for player character added event
- Players.PlayerAdded:Connect(function(player)
- player.CharacterAdded:Connect(onCharacterAdded)
- end)
- -- Check for existing players
- for _, player in ipairs(Players:GetPlayers()) do
- if player.Character then
- onCharacterAdded(player.Character)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment