I have a frame and inside that frame is lots of other frames and inside those frames are buttons.
I know its hard to describe.
But I dont want to define every button individually so I tried this line of code but for some reason its not working.. Can you not have a for loop inside another for loop?
Heres the code
function ButtonClicked()
for i,Child in pairs(script.Parent:GetChildren()) do
if Child:IsA("Frame") then
for i,Child2 in pairs(Child:GetChildren()) do
for i,Child3 in pairs(Child2:GetChildren()) do
if Child3:IsA("ImageButton") then
Child3.MouseButton1Click:Connect(function()
print("Button Clicked")
end)
end
end
end
end
end
end
I know its kinda messy but yeah, its not working so any ideas?

2 comments
It is hard but I know a messed up way
I remember doing this back when I didn’t know what :GetDescendants() was. Just do what Moo said.