Is there a way to tell if the player has been kicked or has left?

The title says it all, is there actually a way to tell the difference?

If I were you, I’d make a BoolValue or some other value in the player which can be checked during the PlayerRemoving event. Any scripts that kick the player would have to be modified to change the value.

1 Like

There is no way to know the nature of how the player was removed from the game afaik (whether they got kicked or left willingly). If you’d like to know this you need to track it yourself.

Out of curiosity why do you want to know if a player was kicked or not?

2 Likes

If you kicked them on the server: You should know. Use a value or something if your scripts are distributed around the place and you want to know in a different script than the kick was issued.

If you kicked them on the client: You won’t know unless you get that info back to the server before the LocalScripts are destroyed. RemoteEvent before the kick might work.

If Roblox kicked them in some way: You won’t know.

In all cases, it looks no different to just leaving the game / disconnecting with bad internet / crashing. If it’s a developer-made action then it shouldn’t be too difficult to let your other developer-made actions know about it.

As H_mzah asked though, why would you want/need to know?

1 Like
local PlayersWhoGotKicked = {}

function Kick(Player, Msg)
	PlayersWhoGotKicked[Player] = Player
	Player:Kick(Msg)
end

game.Players.PlayerAdded:Connect(function(Player)
	if Player.Name == "CoolShank8" then
		Kick(Player, "known exploiter")
	end
end)


game.Players.PlayerRemoving:Connect(function(Player)
	if PlayersWhoGotKicked[Player] then
		print 'hAckEr'
	else
		print 'good boy'
	end
	
	PlayersWhoGotKicked[Player] = nil
end)

Store the players who got kicked in a table, and when the player is leaving remove them from the table while checking if they were in this table, use the function Kick() to automatically add them into the table instead of you manually doing it.

Basically you need to “tag” the player when you kick him so when he leaves you’ll know if he was kicked.

2 Likes

using the function kick doesnt remove the player from the game, does it?

Oh, Player:Kick() does remove the player from the game. On the client it just shows a screen like this

Kick Screen

However the player is no longer connected to the server

I managed to check the .PlayerRemoving event, I made an anti-cheat for anti-kick exploits. Player:Kick() does remove the player from the game but doesnt remove the player from the database till they press the Leave button. in other words, the player wouldn’t exist after you kick the player. So, try to do Player:Kick() print(Player)

You’ll find that the player still exists and this is what I don’t want. So I make a custom function kicking the player and adding him to a table. and then I wait for 2 seconds and check if the player is in the table then kick him. and also using .PlayerRemoving it will take the player off that table.

So I manage to make an anti-cheat for anti-kick exploits using this way.

Thanks for your help.

1 Like