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