How would I check if a player has left the server?
The PlayerRemoving event of Players fires when a player leaves and passes the player who is leaving. The trick is, it fires just before the player actually gets removed from the game.
local connection connection = game.Players.PlayerRemoving:connect(function(player) if player == p1 then -- your code (if player is p1) connection:disconnect() elseif player == p2 then -- your code (if player is p2) connection:disconnect() -- These prevent connections from stacking on top of each other and causing very bad lag. end end)
EDIT: Edited code to match explanation in comments.
game.Players.PlayerRemoved:connect(function(player) print(.. player.Name .. " has left the server") end)
This will tell you if someone has left and print their name in the output.
You would check if the player is nil, for example:
game.Players.PlayerAdded:connect(function(player) wait() if player == nil then local h = Instance.new("Hint", game.Workspace) h.Text = player.Name.." has left the server!" wait(2) h:Destroy() end end)