I have the following code: local frame = script.Parent.ModeSelection.Layout:FindFirstChild("%l%l%l%lDailyMode")
(Explanation: it need to find the frame with the name xxxxDailyMode, where xxxx are uppercase letters at random (AAAA to ZZZZ).
However, this (obviously) doesn’t work, since Lua can’t find the correct string. How should we I find the correct frame effectively and not very costly (since iterating over the whole list of frames can take quite some time, which I don’t want).
Thank you in advance!
You would instead of using instance:FindFirstChild() have to loop through all children of script.Parent.ModeSelection.Layout, after which you check if the name is equal to "%l%l%l%lDailyMode", if it is equal to that name then you run your code.
local layout = script.Parent.ModeSelection.Layout
local DailyMode
for _, frame in pairs(layout:GetChildren()) do
if frame.Name == "%l%l%l%lDailyMode" then
-- Code
-- DailyMode = frame (read extra note)
-- break (read note)
end
end
Note, the script will probably fire multiple times so if you want it to fire only once use break at the end of the if statement.
What you can do as well is transfer the instance to a variable (and break the for loop).