To make code run when a player leaves the game, you can use the PlayerRemoving event. To make it limited to a specific player, you can simply add an if statement to check if the player's name matches that of a string value. Here is an example:
local StringValue = game.Workspace.StringValue
game.Players.PlayerRemoving:Connect(function(Player)
if Player.Name == StringValue.Value then
end
end)
I would recommend storing the value inside of your script to prevent exploiting, but for this example all you would have to do is change the StringValue variable to the directory of your value. (If your value is in the workspace, you should only have to change the directory to the name of your string value.) Hope this helped, good luck!
6 comments
Maybe make a RemoteFunction that the client calls in a loop to report to the server that it's still connected. Keep a record of when the last time the player called that function was. When a player leaves, check how long ago their last response on that RemoteFunction was.
@ABK2017 Why, the player(on PlayerRemoving event) is the player object(player.Name is the player name)
ABK2017 your answer makes no sense
and it is not helpful.
Also it would not be efficient at all
No it would not be so efficient...but if the time of the RF exceeded the loop time, clearly that player has left the game, that's all I meant.