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.
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)