How to detect when a specific player leaves

I have assigned a specific player in my game to ‘player1’ and I was wondering if there was a way to detect if that player leaves the game. Because Players.PlayerRemoving seems to just detect when any player leaves. Thanks

depends when you need to start detect:

essentially you will want to use player.PlayerRemoving

need more context though… why do you want a specific player

1 Like

PlayerRemoving event returns the player that is removing as a param.
So you could have a simple if statement that checks if that player equals your “specific player”. Whether that is directly with a reference or something like userid.

1 Like

Pretty simple:

game.Players.PlayerRemoving:Connect(function(player)
    if player.Name(Or .UserId.) == ---(Whatever you want to  put here e.g Username, UserId, etc.). then
        ---(Your code here)
    end
end)

Wrote this on my phone so it might not be correct.

1 Like

You would want to do player.Name / player.UserId, comparing a userdata to a string/number won’t work.

1 Like
game.Players.PlayerRemoving:Connect(function(player)
    if player.Name == "name_here" then 
          -- do stuff
    end
end)

put the “name_here” as the player’s name

1 Like

you can also change the if statement to “if player.UserId == id here” btw. Remember to put the “id here” as the player’s id.

1 Like

Yeah, I was going to do that but didn’t. Sorry

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.