Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

?How to detect when localplayer left the game

Asked by 4 years ago

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

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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)
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 blox_develop 2 — 4y
0
It will do exactly what you wish, just operate via LocalScript. Ziffixture 6913 — 4y
0
Oh ok i understand now! Thanks blox_develop 2 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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)

Answer this question