Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)


2 comments

0

I don't think that will work..?

0

getchildren makes a table so no i dont think that would work.

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.