Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Kick script not working? Can someone please help?

What I'm looking for this script to do is allow the people in the "Allowed" table to join the server, but if they're not on the table, their game auto shuts down, but it seems to be kicking everyone, including the Allowed table. Anyone know what I did wrong?

It seems that adding more to the Allowed table breaks it, but I thought you could add more?

Allowed = {"Exbryst"}

game.Players.ChildAdded:connect(function(player)
	for _,v in pairs (Allowed) do
		if player.Name:lower() == v:lower() then
			print("Allowed in.")
		else
			player:Kick()
		end
	end
end)

1 answer

This will work, if there is only one player in the allowed list.

Consider there are two names, A, and B.

Your script will do something like this.

  • A

    • Is the player A?
    • If so, print
    • If not, KICK THEM
  • B

    • Is this player B?
    • If so, print
    • If not, KICK THEM

What's the trouble?

What about player B? When they join, they aren't player A, and will be kicked.


We want them to match any one, not all of them.

Here's two (more or less equivalent) ways to do that:

Allowed = {"Exbryst"}

game.Players.ChildAdded:connect(function(player)
	for _,v in pairs (Allowed) do
		if player.Name:lower() == v:lower() then
			print("Allowed in.")
			return -- Flee before being kicked!
		end
	end
	player:Kick() -- Wasn't found in the cool-kids list
end)
Allowed = {"Exbryst"}

game.Players.ChildAdded:connect(function(player)
	coolKid = false -- So far, not a cool kid.
	for _,v in pairs (Allowed) do
		if player.Name:lower() == v:lower() then
			print("Allowed in.")
			coolKid = true -- We now know they're a cool-kid
		end
	end
	if not coolKid then
		player:Kick() -- Wasn't found in the cool-kids list
	end
end)

Also, Tkdriverx is right, you should probably use PlayerAdded, though that also won't be necessary.

This discussion is preserved as it was. New answers, comments, and votes are closed.