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: Regarding listeners and not-so-elegangt code

Previous Thread :: Next Thread 
Fakecake777 is not online. Fakecake777
Joined: 19 Nov 2012
Total Posts: 441
25 Dec 2013 06:09 AM
I'm writing a script that creates a new part at the click of a button, up to 20 parts, and removes a part when that part is clicked. The parts positions are set so that they are in a nice grid of 5*4. How ever, to check when a part is clicked, I've got up to 20 different click detectors, and therefor up to 20 listeners:

This is not nice, so I am wondering if there is a better, less "bulky" way to do it.

script.Parent.Parent.slots.slot1.MouseClick:connect(click2)
script.Parent.Parent.slots.slot2.MouseClick:connect(click2)
script.Parent.Parent.slots.slot3.MouseClick:connect(click2)
script.Parent.Parent.slots.slot4.MouseClick:connect(click2)
script.Parent.Parent.slots.slot5.MouseClick:connect(click2)
script.Parent.Parent.slots.slot6.MouseClick:connect(click2)
script.Parent.Parent.slots.slot7.MouseClick:connect(click2)
script.Parent.Parent.slots.slot8.MouseClick:connect(click2)
script.Parent.Parent.slots.slot9.MouseClick:connect(click2)
script.Parent.Parent.slots.slot10.MouseClick:connect(click2)
script.Parent.Parent.slots.slot11.MouseClick:connect(click2)
script.Parent.Parent.slots.slot12.MouseClick:connect(click2)
script.Parent.Parent.slots.slot13.MouseClick:connect(click2)
script.Parent.Parent.slots.slot14.MouseClick:connect(click2)
script.Parent.Parent.slots.slot15.MouseClick:connect(click2)
script.Parent.Parent.slots.slot16.MouseClick:connect(click2)
script.Parent.Parent.slots.slot17.MouseClick:connect(click2)
script.Parent.Parent.slots.slot18.MouseClick:connect(click2)
script.Parent.Parent.slots.slot19.MouseClick:connect(click2)
script.Parent.Parent.slots.slot20.MouseClick:connect(click2)
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
25 Dec 2013 06:20 AM
local slot = script.Parent.Parent.slot

for i = 1, 20 do
slot:FindFirstChild("slot"..tostring(i)).MouseClick:connect(click2)
end
Report Abuse
Fakecake777 is not online. Fakecake777
Joined: 19 Nov 2012
Total Posts: 441
25 Dec 2013 06:49 AM
Oh, alright. Thanks a lot
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