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 |
|
|
|
| 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
|
  |
| Joined: 02 Feb 2014 |
| Total Posts: 1041 |
|
| |
|