PlayerRemoving (Event): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>JulienDethurens
No edit summary
Better code
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<onlyinclude>{{Event|name = PlayerRemoving
<onlyinclude>{{Event|name = PlayerRemoving
|arguments = [[Player]] <var>player</var>
  | arguments   = [[Player]] <var>player</var>
|description = Fires when a player is leaving the game.
  | description = Fires when a player is leaving the game.
|object = Players
  | object     = Players
}}</onlyinclude>
}}</onlyinclude>
{{Clear floats}}
{{Example|
This code will print <samp>A player has left: </samp>, followed by the player's name, everytime a player leaves:
<syntaxhighlight lang="lua" line>
local Players = game:GetService("Players")


{{clear floats}}
local function onPlayerRemoving(player)
 
print("A player has left: " .. player.Name)
{{Example|<code lua>
local function onPlayerLeaving(Player)
  print(Player.Name.." is leaving the game!")
end
end


game.Players.PlayerRemoving:connect(onPlayerLeaving)
Players.PlayerRemoving:connect(onPlayerAdded)
</code>}}
</syntaxhighlight>}}
 
== See Also ==
*[[File:Event Icon.png]][[PlayerAdded_(Event)|PlayerAdded]]
* [[File:Event Icon.png]][[PlayerAdded_(Event)|PlayerAdded]]
 
[[Category:Events]]
[[Category:Events]]

Latest revision as of 01:44, 18 April 2023

PlayerRemoving ( Player player )
Description Fires when a player is leaving the game.
Member of: Players
Example

This code will print A player has left: , followed by the player's name, everytime a player leaves:

local Players = game:GetService("Players")

local function onPlayerRemoving(player)
	print("A player has left: " .. player.Name)
end

Players.PlayerRemoving:connect(onPlayerAdded)

See Also