Do connections disconnect when the script is disabled?

Im trying to make an advanced connection manager and I was wondering if disabling a script would cause the connections to disconnect?

Yes, they do disconnect when the script is disabled.

They do not disconnect when a script is disabled. You should try out some situations of your own and see if they disconnect automatically.

No they don’t. A while back when I first started scripting I used to disable my scripts with touch events as a form of debounce and once the script is re-enabled then the connections still run

As @keith_220 said, they do indeed disconnect. They also disconnect if the script it destroyed.

As for these:

When you re-enable a script, it will execute all of its code again. This will make events become active as they’re supposed to. This should not be confused with connections not being disconnected:

local httpService = game:GetService('HttpService')
local scriptId = httpService:GenerateGUID(false)
script.Parent.Touched:Connect(function(part)
	print(part:GetFullName()..' '..scriptId)
end)

If you test this inside of a part and touch it, then disable and re-enable the script (make sure you’re doing this server-side or whichever side your script is on (most likely server in this case)), then touch it again; you find that the GUID is different from the first time. This is a new connection rather than a disconnected connection. You can also find this out because nested events won’t fire again unless they are re-connected by your own code.

8 Likes

Aha, this makes more sense. Thanks for this information and thanks for correcting me!

2 Likes