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

What is :disconnect() used for?

This topic is a bit related to my earlier question How can I disconnect a function?, but now I am wondering what is :disconnect(), I've seen it a few times in a script, but not too sure how it works, or how it is used for what purpose.

1 answer

:disconnect() is used to disconnect events that were connected. Basically, if you had an event that called a function, and you used the disconnect method on the event, the function will no longer be called when the event fires. In order to use it, that even has to be assigned to a variable, like so:

Connection = Part.Touched:connect(onTouch) --Connects the Touched event to the function onTouch
wait(5)
Connection:disconnect() --Disconnects the event

2 comments

0

In what way is the second segment incorrect? The two are equivalent except for global/local scope.

0

Nevermind, I just tested it and it works, so I edited my answer and removed that part

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