Trying to make a code to detect when localplayer left the game but don't know how I would do so.. Anyone know how I could do this? Thanks!
COMMUNITY QUESTION
?How to detect when localplayer left the game
2 answers
You can use the Players service signal PlayerRemoving to listen for a disconnecting Client. This signal will provide the user that is leaving, allowing us to perform an action on them.
local Players = game:GetService("Players")
Players.PlayerRemoving:Connect(function(Removing)
print(Removing.Name.." left the game!")
end)
You can get the removing player by using the PlayerRemoving Function
game.Players.PlayerRemoving:Connect(function(player)
print(player.Name.. "Has left the game :(")
end)
If you press F9 or type /console you can see the text
If you want to see it on a Gui the you have to add a ScreenGui in StarterGui and a TextLabel then a Script in TextLabel:
game.Players.PlayerRemoving:Connect(function(player)
script.Parent.Text = player.Name.. "Has left the game:("
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
What i am trying to do is detect when the localplayer leaves game so that it changes a stringvalue that i have placed in the startergui
It will do exactly what you wish, just operate via LocalScript.
Oh ok i understand now! Thanks