Connections dont disconnect when Script is removed?

According to this page:

signals like DescendantAdded won’t actually disconnect until the object it is associated with is removed, regardless if the script object is still present in the game.

If I have a script like this:

workspace.DescendantAdded:connect(function(part)
	print("Added", part)
end)

It WILL stop running when the script is deleted.
So what use does the connection have if it’s there but doesn’t run any function or work in any way?

2 Likes

Seems like there’s a lot wrong with that Wiki page. I’ll send it to the IX team and ask if they can fix it up.

Connections will disconnect when a script is destroyed, but not the main Lua thread itself.
If you have an infinite loop in the script, deleting the script will not stop that loop.

That article is admittedly out of date, and I do want to go back and work on it at some point. I think the point I was really trying to nail home with that article is that you shouldn’t keep object references lying around if you aren’t using them anymore.

9 Likes

Hmm not quite. Testing this leads me to assume the thread only fully stops when it yields after the script has been destroyed(?).

1 Like

Right, I guess it does stop the Lua thread if you destroy the script.
However, it will continue to run if you set the script’s parent to nil. I believe this is what Studio’s delete option does (so that changes can be undone)

1 Like

That link leads to a page not found for some reason