How does disconnecting events work, and what are the consequences of not doing so

Well… I’m making this post as I recently made an wood chopping script, I’ve been told not disconnecting the “Touched” event can cause a memory leak.

What I want to know now is the main cause of memory leaks, what problems they can bring, and how you can prevent them. Also, how can Hackers use these memory leaks to exploit the game if that’s even possible.

Depends on how you do it.

If you :Destroy() then part afterwards, it should clear all connections automatically, so you should be fine.
As to what it does, it creates memory leaks which are bad since they ultimately lead to increased memory and lag.
Exploiters can’t do much with memory leaks.

In case you’re not :Destroying() the object, you should definitely :Disconnect() all events used on it.

2 Likes

I see, so it can cause increased lag. Good to know.

Check out this thread for more information on the topic of “not disconnecting = memory leaks”:

2 Likes

I just read threw that post and I’m wondering…

Do you really need to put events in a variable just to disconnect it?

2 Likes

If you want to control when it disconnects at a later point in time, yes.

1 Like

Oh okay, so when disconnecting you can do it without variables, good to know.