Check if a string is inside a table

How would I find a string value inside a table

local table1 = {}
local string1 = "String"
table.insert(table1,string1)
table.find(table1,string1)

that was not my code , just an example

Man , I really need to read the whole roblox function library, don’t I.
I tried a loop

for _, v in pairs(table1) do

Don’t really know what to do for the loop since I believe you can’t use getchildren or findfirstchild on a table

1 Like

table.find is correct for what you want to achieve.

local table1 = {"hi"}
local string1 = "hi"
if table.find(table1, string1) then
     -- do stuff
end

Sorry everyone It had another problem (it was basically where in the script it was mistaking the string I am looking for as the player, @YAYAYGPPR is right in this situation

Alright, so we have 2 cases:

1.The table is an array:

local tab = {"Hey","There"}
if table.find(tab,"Hey") then
  --do something
end

2.The table is a dictionary:

local tab = {
["Hey"] = "string1",
["There"] = "string2"
}

if tab["Hey"] then
--do code
end