How to check value is in table

how do i check if a value is in a table
this doesn’t seem to work im literally scrathing my head off.

local bronzeMods = {“SomeStaffOfMine”,“Frepzter”}

game.Players.PlayerAdded:Connect(function(plr)

  if plr.Name == #bronzeMods then
  	print("mod is here")
  end

end)

any way to do this?

You would loop through the table and check if each value is equal to the player that joined.

Example:

game.Players.PlayerAdded:Connect(function(plr)
     for i, v in pairs(bronzeMods) do
          if v == plr.Name then
             print(v.." is a moderator.")
             -- anything here will run if the player has been found to be in the table
         end
     end
end)
1 Like

You can use table.find() to check the entire table and if result isn’t nil then that means the provided value is in the table:

local bronzeMods = {“SomeStaffOfMine”,“Frepzter”}

game.Players.PlayerAdded:Connect(function(plr)

  if table.find(bronzeMods, plr.Name) ~= nil then
  	print("mod is here")
  end
end)

you can just put table.find instead of adding Nil to it. ( both will work )

local bronzeMods = {“SomeStaffOfMine”,“Frepzter”}

game.Players.PlayerAdded:Connect(function(plr)

  if table.find(bronzeMods, plr.Name) then
  	print("mod is here")
  end
end)