Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Why wont this work correctly?

Asked by 9 years ago
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)

3 answers

Log in to vote
3
Answered by
Tigerism 220 Moderation Voter
9 years ago

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)

Ad
Log in to vote
2
Answered by 9 years ago

loop through the table

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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)
1
:p put a comma on the first element in table Tigerism 220 — 9y
0
oh my bad lol Perci1 4988 — 9y

Answer this question