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!
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.
1 | local Players = game:GetService( "Players" ) |
2 |
3 | Players.PlayerRemoving:Connect( function (Removing) |
4 | print (Removing.Name.. " left the game!" ) |
5 | end ) |
You can get the removing player by using the PlayerRemoving Function
1 | game.Players.PlayerRemoving:Connect( function (player) |
2 | print (player.Name.. "Has left the game :(" ) |
3 | 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:
1 | game.Players.PlayerRemoving:Connect( function (player) |
2 | script.Parent.Text = player.Name.. "Has left the game:(" |
3 | end ) |