local List = {'Player', 'UltraUnitMode'}
game.Players.PlayerAdded:connect(function(plr)
if plr.Name == List then
return true
elseif plr.Name ~= List then
plr:Destroy()
end
end)
✓ ANSWER ACCEPTED
Why wont this work correctly?
3 answers
✓ Accepted answer
You need to loop through the table using a for loop.
Code:
game.Players.PlayerAdded:connect(function(plr)
local success = false
for i,v in pairs(List) do
if v == plr.Name then
success = true
end
end
if not success then
plr:Destroy()
end
end)
loop through the table
List is literally a list. How could your name ever equal a list? That makes no sense.
What you want to do is find if your name is inside the list.
We could use a for loop to compare each item to your name, writing a function like this:
function isInList(name)
for i, v in pairs(List) do
if name == v then
return true
end
end
end
But an easier method would be to make use of dictionaries;
local List = {
["Player"] = true,
["UltraUnitMode"] = true
}
game.Players.PlayerAdded:connect(function(plr)
if not List[plr.Name] then --if you're not in the list
plr:Kick() --use kick() instead of destroy()
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
:p put a comma on the first element in table
oh my bad lol