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

What is :disconnect() used for?

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

: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
0
In what way is the second segment incorrect? The two are equivalent except for global/local scope. BlueTaslem 18071 — 10y
0
Nevermind, I just tested it and it works, so I edited my answer and removed that part TurboFusion 1821 — 10y
Ad

Answer this question