Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can't make a function run when clicking a descendent using GetChildren()?

Asked by 6 years ago

Hi, I was wondering how I can, if possible, make a function run if one of the descendents is clicked when I use GetChildren()? Is there another way besides making a function for each individual button?

local buttons = script.Parent.Frame:GetChildren()

buttons.MouseButton1Click:Connect(function()
    print("click")
end)


0
I don't think that will work..? cherrythetree 130 — 6y
0
getchildren makes a table so no i dont think that would work. DinozCreates 1070 — 6y

1 answer

Log in to vote
2
Answered by
Rheines 661 Moderation Voter
6 years ago

You need to connect a clicked event on the button's children using a for loop.

local buttons = script.Parent.Frame:GetChildren()
--Connecting click events on the button's descendants.
for _,v in pairs(buttons) do
    v.MouseButton1Click:Connect(function()
        print("click")
    end)
end
Ad

Answer this question