I cam across an error in my code and was wondering if i were to make a localscript on a player and attach a function to game.Players.PlayerRemoving which triggers when the local player has left, would the script run when they click leave/before they actually leave? or would it just not run since the player isnt there? I know you could make this script work on a server side script but im just curious
COMMUNITY QUESTION
Can you make a localscript run when player leaves?
1 answer
This would work both server sided and local sided If you want it in local script do this in StarterPlayerScript Here's and article on PlayerRemoving
script:
game.Players.PlayerRemoving:Connect(function(player)
local player = game.Players.LocalPlayer
print("A player has left: " .. player.Name)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Where did you put the LocalScript? LocalScript's only work in a player's gui, scripts, or tools.
The script would not work because the client has disconnected, so the scripts don't exist because the player doesn't exist.
?