The CharacterRemoving event fires right before a player’s character is removed, such as when the player is respawning.
This event can be used alongside the
Player/CharacterAdded event, which fires when a player’s character spawns or respawns. For instance, if you would like print a message every time a player spawns and dies:
local Players = game:GetService("Players") local function onCharacterSpawned(player) print(player.Name .. " is spawning") end local function onCharacterDespawned(player) print(player.Name .. " is despawning") end local function onPlayerAdded(player) player.CharacterAdded:Connect(function () onCharacterDespawned(player) end) player.CharacterRemoving:Connect(function () onCharacterDespawned(player) end) end Players.PlayerAdded:Connect(onPlayerAdded)
This event is only concerned with the
Player/Character|Character of a
Player. If you instead need to track when a player joins/leaves the game, use the events
An instance of the character that is being removed.
This example prints the name of the character being removed, followed by “has died”.
For instance, if Shedletsky’s character was to die in-game, “Shedletsky has died.” would be printed.