PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. Instead, you should go to our new and improved documentation. You can also learn more about the future of documentation.
Collapse Sidebar

PlayerRemoving

The PlayerRemoving event fires right before a Player leaves the game. This event fires before Instance/ChildRemoved|ChildRemoved does on Players, and behaves somewhat similarly to Instance/DescendantRemoving. Since it fires before the actual removal of a Player, this event is useful for storing player data using a GlobalDataStore.

This can be used alongside the Player/PlayerAdded event, which fires when a player joins the game. For instance, to print a message every time a new player joins or leaves the game:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
  print(player.Name .. " joined the game!")
end)

Players.PlayerRemoving:Connect(function(player)
  print(player.Name .. " left the game!")
end)

If you want to track when a player’s character is added or removed from the game, such as when a player respawns or dies, you can use the Player/CharacterAdded and Player/CharacterRemoving functions.

Parameters

Name Type Default Description

An instance of the player that is leaving the game.


Code Samples


Players.PlayerRemoving

This code will print "A player has left: ", followed by the player’s name, every time a player leaves: