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

How do you check if a players name is in a table?

Asked by 9 years ago
-- owner and moderator assets
owner = {"devSchon","Player1"}
moderator = {}

if script.Parent.Parent.Name == owner then
    script.Parent.OwnerAssets.Notifier.Visible = true
end

What I'm trying to do is to check if the player's username matches the users in the "owner" table; then make a GUI visible.

Thank you in advance for your help!

2 answers

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
9 years ago

Using a for loop is the best option because you can loop through each individual value within the table and check if it matches.

-- owner and moderator assets
owner = {"devSchon","Player1"}
moderator = {}

for _, player in pairs(owner:GetChildren()) do --Creates a loop, where "player" is the value being iterated upon.
if script.Parent.Parent.Name == player then
    script.Parent.OwnerAssets.Notifier.Visible = true
end
end

If I helped you, be sure to accept my answer! :D

0
It does not work, all I'm doing in "script.Parent.Parent.Name == owner" is checking each player to see if their name is equal to a string in the owner table. Could that be the problem? SchonATL 15 — 9y
0
Yes that is, that's not gonna work at all, you're comparing a string value to a table, not the table's values. legobuildermaster 220 — 9y
0
The only issue here is that you're calling`GetChildren` on a table... you should only use it with instances to GET a table. ImageLabel 1541 — 9y
0
On line 6, it says "script.Parent.Parent.Name == player" not "owner" Discern 1007 — 9y
Ad
Log in to vote
0
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

You simply need to iterate through the table in search for the particular object or value you want to evaluate. You can use any iterator function, which along with a generic for loop would do just what you need.

owner = {"devSchon","Player1"} moderator = {}

for index, value in pairs(owner) do if script.Parent.Parent.Name == value then -- found end end

Answer this question