Tyecon
|
  |
| Joined: 19 Apr 2009 |
| Total Posts: 2908 |
|
|
| 01 Apr 2012 11:09 AM |
buttons=script.Parent.Buttons:GetChildren(); for k, v in pairs(buttons) do if (v:FindFirstChild("ClickDetector")) then v.ClickDetector.MouseClick:connect(ButtonClick(v)); end end
I want to allow the ButtonClick(button) function to fire if any brick with a ClickDetector in Buttons is clicked, regardsless the amount of buttons. I'm just not sure how to connect all these events. The script I posted up there fires it once for every button at first run. |
|
|
| Report Abuse |
|
|
UFAIL2
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 6905 |
|
|
| 01 Apr 2012 11:13 AM |
buttons=script.Parent.Buttons:GetChildren() for _, v in pairs(buttons) do if v:FindFirstChild("ClickDetector") then v.ClickDetector.MouseClick:connect(ButtonClick) end end
~When life gives you lemons, you say 'I ain't even mad'.~ |
|
|
| Report Abuse |
|
|
UFAIL2
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 6905 |
|
|
| 01 Apr 2012 11:15 AM |
Better script. for _, v in pairs(script.Parent.Buttons:GetChildren()) do if v:FindFirstChild("ClickDetector") then v.ClickDetector.MouseClick:connect(function() --code end) end end
~When life gives you lemons, you say 'I ain't even mad'.~ |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2012 11:16 AM |
buttons=script.Parent.Buttons:GetChildren(); for k, v in pairs(buttons) do if (v:FindFirstChild("ClickDetector")) then v.ClickDetector.MouseClick:connect(function(clicker) ButtonClick(v,clicker) end); end end
ButtonClick is called with the first argument as the part, and the second is the player who clicked it. |
|
|
| Report Abuse |
|
|
Tyecon
|
  |
| Joined: 19 Apr 2009 |
| Total Posts: 2908 |
|
|
| 01 Apr 2012 12:08 PM |
| Ah that last one works, thank you! |
|
|
| Report Abuse |
|
|