PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

CharacterRemoving

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 Players/PlayerAdded and Players/PlayerRemoving.

Parameters

Name Type Default Description

An instance of the character that is being removed.


Code Samples


Player.CharacterRemoving

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.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterRemoving:Connect(function(character)
        print(character.Name .. " has died.")
    end)
end)