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 » Scripters
Home Search
 

Disconnect multiple functions

Previous Thread :: Next Thread 
Inigo18 is not online. Inigo18
Joined: 02 Feb 2014
Total Posts: 1041
02 Apr 2017 04:53 AM
So I'm trying to make a GUI where you can drag multiple elements, so I add a DragBegin event in every frame by doing:

for i = 1,#a do
a[i].DragBegin:connect(function() DragStart(a[i])
end)

The problem is that later on, I need to re-define a, so after defining a I write that piece of code again. However, the function will now run two times when I start dragging it and so on. I know that I could add a variable to the function and then disconnect it, but since its a for loop I don't think I can do that.
Anyone knows how to solve this?
Thanks!


Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
02 Apr 2017 04:57 AM
:connect is deprecated, use Connect
\\
insert all connections into a table

local connections = {}

for i = 1,#a do
table.insert(connections,a[i].DragBegin:Connect(function()
DragStart(a[i])
end))
end)

--disconnect
for i=1, #connections do
connections[i]:Disconnect()
end


capitalist atheist
Report Abuse
Inigo18 is not online. Inigo18
Joined: 02 Feb 2014
Total Posts: 1041
02 Apr 2017 04:58 AM
Awesome, thanks!!


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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