Basically, I have the same 30 local variables with the incremental numbers in the end. What I want is this end result
for num = 1, 20 do local Question..num = script.Parent.Question..num..Frame end
Instead of the messy lines of code like this:
local Question1 = script.Parent.Question1Frame local Question2 = script.Parent.Question2Frame local Question3 = script.Parent.Question3Frame -- So on
How do I go about using a for loop for this situation?
I figured out the solution! By using tables as suggested by Qariter and learning how to convert String to Instance, from this link: https://devforum.roblox.com/t/convert-string-to-instance/385716 I've come up with this block of code:
local Question = {} for index = 1, 20 do local dir = "Question"..index.."Frame" local segments = dir:split(".") local current = script.Parent --location to search for i,v in pairs(segments) do current=current[v] end table.insert(Question, current) end
I tested it out and it worked successfully!