Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

?How to detect when localplayer left the game

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!

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)

3 comments

0

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

0

It will do exactly what you wish, just operate via LocalScript.

0

Oh ok i understand now! Thanks

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.