Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to disconnect all event's?

Asked by 4 years ago
local plr = game.Players.LocalPlayer
local rep = game.ReplicatedStorage
events = {}

script.Parent:WaitForChild("start").MouseButton1Click:Connect(function()
script.Parent.nums.Visible = true
for i,v in pairs(script.Parent.nums:GetChildren()) do
local first = v.MouseButton1Click:Connect(function()
for i,e in pairs (events) do
e:Disconnect()
e = nil
end
print(#events)
end)
table.insert(events,first)
end
print(#events)
end)

Basically i put the event's in a table then i scan through the whole table and try to disconnect them all but when i print #events after i disconnected them AND made them nil it still says 6 event's??

1
They are disconnecting. You just still have a reference to the variables in memory (because of the table). Set the values in the table to nil. royaltoe 5144 — 4y
0
You can make your table weak if you want it to garbage collect: https://devforum.roblox.com/t/garbage-collection-and-memory-leaks-in-roblox-what-you-should-know/374954 royaltoe 5144 — 4y

Answer this question