I want to make something happen when one of several buttons is clicked. All the buttons are text buttons, parented to a frame. The following code gives me an error like this: attempt to index field "MouseButton1Click" (a nil value)
Any help on how to make this work would be appreciated.
local buttons = script.Parent.Frame:GetChildren() buttons.MouseButton1Click:connect(function() print("It works!") end)
Here's a link to a SH help post about the subject.
Loop though the table and add the event to each button. This is fairly easy. Example,
local buttons = script.Parent.Frame:GetChildren() for i,v in pairs(buttons) do v.MouseButton1Click:connect(function() print("It works!") end) end
Good Luck!