Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is disconnecting and how is it useful?

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)?

2 comments

0

well, what does :Connect() do

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.

1 answer

: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!

This discussion is preserved as it was. New answers, comments, and votes are closed.