for i,v in pairs(table) do if string.find(v, text) then TextLabel1.Text = v TextLabel2.Text = v end end
For the script above I want to make it so it loops through a table's values, sees if "text" is found in v and then change two text labels. I want the 1st text label's text to be another value from the other text label. For example if from the string.find 3 different values are returned, I want textlabel1's text to be the 1st value, textlabel2 text to be the 2nd etc. But I've tried everything, inserting the values into a table, but nothing worked. Thank you
You cannot use "table" for it is a data type.
Put an if statement in your for loop to see if TextLabel1 has anything in it, if not then put v there. If there is something then put it into TextLabel2 instead.
local myTable = {"Shoes","Apples","Bicycle","Shoes"} local text = "Shoes" local TextLabel1 = nil local TextLabel2 = nil for i,v in pairs(myTable) do if string.find(v,text) then -- If TextLabel1 already has v stored then it will store -- v into TextLabel2 if not TextLabel1 then TextLabel1 = v else TextLabel2 = v end end end print(TextLabel1) print(TextLabel2)