Whitelist not working

I made a simple whitelist script, but when I playtest the game, it kicks me even though I am whitelisted

The following script is a serverscript

local whitelisted = {"ryanthapro","Mshistyy","HELLOSIRIMADUD"}
game.Players.PlayerAdded:Connect(function(plr)
	for i = 1, #whitelisted do
		if plr.Name == whitelisted[i] then
			plr:Kick()
		end
	end
end)

You’re checking if the player’s in the whitelist, and kicking them if they are. Your code can just be simplified to this:

local whitelist = { --[[names]] }

game:GetService("Players").PlayerAdded:Connect(function(player: Player)
    if (not table.find(whitelist, player.Name)) then
        player:Kick()
    end
end)

table.find will return the key of the table the element is in, and if the element isn’t in the table it returns nil. not nil is true, so we are basically saying “if the player isn’t in the whitelist”.

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