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

Can you make a localscript run when player leaves?

Asked by
Faazo 84
4 years ago

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

0
Where did you put the LocalScript? LocalScript's only work in a player's gui, scripts, or tools. youtubemasterWOW 2741 — 4y
0
The script would not work because the client has disconnected, so the scripts don't exist because the player doesn't exist. killerbrenden 1537 — 4y
0
? JesseSong 3916 — 4y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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

Answer this question