Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is disconnecting and how is it useful?

Asked by 6 years ago

What is the purpose of using :Disconnect() to disconnect something? Is it to clear the memory and prevent memory leaks?

I've personally never used it, how do you use it and what is it for (wiki doesn't explain clearly)?

0
well, what does :Connect() do User#24403 69 — 6y
0
I already know it connects to a function, but why would you want to disconnect a function such as the one on the 'OnUpdate' wiki page. YabaDabaD0O 505 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago

:Disconnect() justs disconnects a connection. Here's an example

local connection = part.ClickDetector.MouseClick:Connect(function()
    print("Clicked!")
end
wait(5)
connection:Disconnect()

What that does is it creates a connection, and when you click the ClickDetector it prints out "Clicked!". After 5 seconds, it won't print "Clicked!" again cause the connection has been disconnected.

If you still don't understand it, feel free to ask!

Ad

Answer this question