How would I stop it from kicking players in the table

I don’t want it to kick players inside of the table

It kicks everyone out.

image

using [plr.Name == List ] is a very incorrect thing to do.

try to make a for loop, checking each array in the table to make sure the player’s name surpass each value. what you did in your code checks for all arrays in one value (plr.Name = {"blacksuspect…)

1 Like

You have to do:

if table.find(List, plr.Name) then

To make your code shorter you can do:

if not table.find(List, plr.Name) then
    plr:Kick()
end

@doyouevenbruh33
Making a for loop isn’t really good for this situation, as table.find is much better.

1 Like

Hey, also you need to know this:

Or you could use a table.find()…

Not exactly. For loops are great for any situation where you need to find a value in a table

1 Like

That’s literally what table.find is for, finding values in tables.

Pretty much, here is the code i guess…

local ListOfPlayers = {"blacksuspect", "PlayerNameHere", "BlackDreon"}

game.Players.PlayerAdded:Connect(function(plr)
    for i, v in pairs(ListOfPlayers) do
        if plr.Name == v then 
            --Le code here 
        elseif plr.Name ~= v then
            plr:Kick("Begone, you don't have access to this game.") -- I guess you should remove the "Begone".
        end
    end 
end)

For loops, for the purpose of finding values, and table.find both function the same way, so you can use either one. It depends on personal preference

2 Likes