grandisy
(Grand)
August 9, 2022, 3:56pm
#1
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
YAYAYGPPR
(Yayay27)
August 9, 2022, 3:59pm
#2
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
grandisy
(Grand)
August 9, 2022, 4:01pm
#3
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
Valkyrop
(JustAGuy)
August 9, 2022, 4:35pm
#4
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