Kicked player not really kicked

I am unsure if this is an issue on my side or if it’s a Roblox bug so I decided to post it in the scripting support category.

  1. What do you want to achieve? Keep it simple and clear!
    I want that when a player who is not in the group or is above a certain rank gets kicked.
  2. What is the issue? Include screenshots / videos if possible!
    In the output it says that I got kicked but the kick-GUI doesn’t show up and I can still interact with things like in-game GUIs. Sometimes the in-game GUI doesn’t load at all and my camera just freezes.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried kicking the player from a localscript instead of a serverscript but it did not work. I also scrolled through a few posts in the devforum but I couldn’t really find a post related to this.
    My code:
game.Players.PlayerAdded:Connect(function(player)
	if player:GetRankInGroup(groupId) >= rank or player:GetRankInGroup(groupId) == 0 then
			player:Kick("Access Denied.")
	end
end)
2 Likes

If your game is owned by a group you don’t need to kick someone from the game to achieve this. When you publish it just tick “Group Members Only” for who can play.

1 Like

You are right, the thing is that I also want to kick people above a certain rank.

1 Like

Are you testing with an account that is not in the group?

1 Like

No, I am testing it with my main account. (should still kick me since I am above the maximum rank)
Also, no idea if that info is necessary but I am play-testing in studio. Not sure if that could have something to do with that even though I doubt it since it has worked in other games before.

There’s your reason. In a live game, it will work as expected.

When ensuring people do not join due to other things such as not meeting age requirements, I have a workaround. You would disable the Players.CharacterAutoLoads property and Player.LoadCharacter() if they meet the requirements.

local players = game:GetService("Players");
players.CharacterAutoLoads = false;

players.PlayerAdded:Connect(function(p)
	p.CharacterAdded:Connect(function(c)
		local humanoid = c:WaitForChild("Humanoid");
		if humanoid then
			humanoid.Died:Connect(function()
				task.wait(players.RespawnTime)
				p:LoadCharacter()
			end)
		end
	end)
	
	local groupId = 0; local rank = 1;
	local statements = (p:GetRankInGroup(groupId) >= rank)
	if statements == true then
		p:LoadCharacter()
	else p:Kick("You have been kicked for not meeting the requirements set forth by the experience's developer!") end
end)
2 Likes

Tell me what this prints;

game.Players.PlayerAdded:Connect(function(player)
        print(player:GetRankInGroup(groupId))
        print(rank)
	if player:GetRankInGroup(groupId) >= rank or player:GetRankInGroup(groupId) == 0 then
		player:Kick("Access Denied.")
	end
end)

Interesting, it worked in a live game. What I am confused about is why it suddenly doesn’t work on a local game because I always play-test in studio and it did work before. Could it eventually be some kind of engine “bug” because according to the output I did get kicked, it’s just that I could still interact with in-game GUIs and the normal Roblox kick-GUI didn’t pop up.

Possibly. I remember the Kick UI popping up as well — regardless of whether it was in studio or a live game. Maybe it’s just an undocumented intentional change… who knows :person_shrugging:

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