My Un-Authorized Player Kicker is not working

My Un-Authorized Player Kicker is not working but I put my userID and my friend’s UserID
but when we join it keeps saying this “You are not whitelisted!”
even thou my userid is there here are the photos and code

Code by @b_oolean

local Whitelisted = {1029635682,671819746} -- Use player ids as its more secure if a player was to change their username.
game.Players.PlayerAdded:Connect(function(player)
for i,v in pairs(Whitelisted) do
    if player.UserId == v then -- they're whitelisted!
        print("Developer allowed to join!")
    else -- their id wasnt found in the table
        player:Kick("You are not whitelisted!")
    end
    end
end)

Here are the pics
image
image

1 Like

The issue is that if the first ID in the table is not yours, it instantly kicks you because of the else.

if not table.find(Whitelisted, player.UserId) then
    player:Kick("You are not whitelisted!")
end

Instead of reinventing the wheel, use table.find. It returns nil if it cannot find the second argument in the first argument (table)

3 Likes

Nice thank you for the solution man im just a beginner thou