There isn’t much to say, I just want to know if it is possible to disconnect functions that are called like this:
for i=1, 100 do local part = Instance.new("Part",workspace) local touch = part.Touched:Connect(function() print(part) touch:Disconnect() --I want the function to disconnect once it is fired wait(1) print("doesn't work") end) wait(.1) end
WHAT I’VE TRIED:
- If I make “touch” a global variable it doesn’t seem to be disconnecting the function, and if I keep it as a local one, it prints an error saying that I tried to disconnect a nil value.
(I know it’s not a lot, I just don’t have any other ideas)
I would like to know what’s the easiest or most efficient way to do this, any help is greatly appreciated, and if it just can’t be done, it would still be nice to know.
NOTE: I do know that destroying the parts will disconnect the functions automatically, but I don’t want this to be an option, I only want the parts to live without calling the function more than once.