Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

-- 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

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

4 comments

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?

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.

0

The only issue here is that you're callingGetChildren on a table... you should only use it with instances to GET a table.

0

On line 6, it says "script.Parent.Parent.Name == player" not "owner"

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

This discussion is preserved as it was. New answers, comments, and votes are closed.