generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Connecting unknown number of events

Previous Thread :: Next Thread 
Tyecon is not online. 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 is not online. 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 is not online. 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
ScriptWeb is not online. ScriptWeb
Joined: 27 Oct 2010
Total Posts: 1
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 is not online. Tyecon
Joined: 19 Apr 2009
Total Posts: 2908
01 Apr 2012 12:08 PM
Ah that last one works, thank you!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image