What are the different ways a connection can disconnect

As the title says, what can make a connection disconnect. All I know is by using connection:Disconnect(), and when a script with that connection gets :Destroy()

Also is this going to disconnect the connection?

local connections = {}
connections[1] = SomeInstance.SomeEvent:Connect(SomeFunction)
connections = nil

Nope, remember

The script exists, and the connection as well, it’s just stored in nil.

Edit: whoops I was talking about this one below and how the connection is running but stored in nil. Anyways seems like @Lielmaster is able to test it yourself so it should be fine.

:Destroy() is not just setting the parent property to nil, it sets the parent of the object to nil, locks the parent property, and if it is a script, it disconnects all connections in that script, though the thread is still running. Test this code

workspace.ChildAdded:Connect(function()
	print("ChildAdded")
end)

task.delay(5, function()
	print("Destroying script in 5 seconds")
	task.wait(5)
	script:Destroy()
end)

while true do
	task.wait(1)
	local part = Instance.new("Part",workspace)
	task.wait(1)
	part:Destroy()
end

It will still insert parts but it wont print anymore

You could have just replied again instead of edit.

I actually tested it and i thought it will disconnect, but it did not, so I just added it to my question. That is not my main question though

Well, that’s pretty much it, you listed all the two ways to disconnect an event as indicated in this Roblox article👍:

https://developer.roblox.com/en-us/articles/events

Even if there was a third way it would be pretty extra and unneeded.

1 Like