Pepperpants

Roblox Kick on Death

Jun 16th, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. -- Get the Players service
  2. local Players = game:GetService("Players")
  3.  
  4. -- Function to handle player deaths
  5. local function onCharacterAdded(character)
  6. local humanoid = character:WaitForChild("Humanoid")
  7.  
  8. -- Listen for humanoid death event
  9. humanoid.Died:Connect(function()
  10. -- Kick the player when they die
  11. local player = Players:GetPlayerFromCharacter(character)
  12. player:Kick("You died!")
  13. end)
  14. end
  15.  
  16. -- Listen for player character added event
  17. Players.PlayerAdded:Connect(function(player)
  18. player.CharacterAdded:Connect(onCharacterAdded)
  19. end)
  20.  
  21. -- Check for existing players
  22. for _, player in ipairs(Players:GetPlayers()) do
  23. if player.Character then
  24. onCharacterAdded(player.Character)
  25. end
  26. end
Advertisement
Add Comment
Please, Sign In to add comment