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

why isnt this working?

Asked by
MHaven1 159
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
if user.Name == {"MHaven1" , "Player2", "Player1"} then
print("Admin")
else
print ("Not Admin")

this will not print 'Admin' if any one of the player in the list sits in the car. please help

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

Assuming that user.Name actually is one of the names you're trying to compare to, there are 2 main issues with your code. Firstly you're missing an end after print("Not Admin"), secondly you're trying to compare a string to a table. To compare the table to user.Name you need to look at each value of the table independantly. This can be done with the following code:

local isntAdmin=true--To keep track of whether or not the player is an admin
for i, v in pairs({"MHaven1" , "Player2", "Player1"}) do--Loop through the table
    if user.Name==v then
        print("Admin") --user.Name is an admin
        isntAdmin=false --Keep track that one of the names is equal to user.Name
    end
end
if isntAdmin then
    print("Not Admin")
end

Ad

Answer this question