Do signal connections disconnect on script destroy?

Hello all,

I have a two part question:

  1. I recall somewhere I read that any signal connections done from a script will disconnect when the script is destroyed. Is this true? Is it true for all signal connections, i.e. on BindableEvents or Instances external to the script?

  2. If I require a module and run a function which creates a script connection, will that connection disconnect on destruction of the original script what required the module?

Yes to both.

  1. When a script or thread that creates a script connection is deleted via :Destroy or the thread is closed, the connection will be disconnected as well.

  2. Scripts cache the modulescript they require, so all it’s doing is storing the modulescript’s data. So, anything you do in that script is still “owned” by the thread it creates, which is closed when the script is destroyed or stops running.

3 Likes

Thanks so much, I didn’t know this applied to coroutines as well, thank you

To clarify- it doesn’t apply to coroutines because they don’t actually generate their own thread. They just run in parallel to the one it was created in. So script connections you connect in a coroutine will still need to be disconnected before the coroutine is closed or yielded.

2 Likes

Does task.spawn() return a new thread which can clean up its connections? Im reading the docs and it says it returns the scheduled thread but now I am confused because I thought task.spawn() and coroutine.create() were pretty much the same.

I have tested and confirmed the task library and coroutines behave the same. Thanks again.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.