Disconnect (Method): Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>ArceusInator
No edit summary
>Flurite
No edit summary
Line 1: Line 1:
<noinclude>{{Method
<noinclude>{{Method
|name = disconnect
|name = disconnect
|description = Disconnects a function from an event so it is no longer active.
|description = Disconnects a function from an event so it is no longer active.  
|object = Event
|object = Event
}}
}}
Line 10: Line 10:
Below is an example of connecting a function and then disconnecting it.
Below is an example of connecting a function and then disconnecting it.
<pre>
<pre>
local Connection = script.Parent.Touched:connect(function()
local Connection = script.Parent.Touched:connect(function()  
print("Hit")
print("Hit")
end)
end)


Connection:disconnect()
Connection:disconnect() --the function will no longer print "Hit" when the script's Parent is touched.
</pre>
</pre>
}}[[Category:Methods]]
}}[[Category:Methods]]

Revision as of 19:17, 10 October 2011

disconnect( )
Returns nil
Description: Disconnects a function from an event so it is no longer active.
Member of: Event


Example

Below is an example of connecting a function and then disconnecting it.

local Connection = script.Parent.Touched:connect(function() 
print("Hit")
end)

Connection:disconnect() --the function will no longer print "Hit" when the script's Parent is touched.

There's also a method name Disconnect in CustomEvent.


Disconnect( CustomEventReceiver receiver )
Returns nil
Description: Disconnects the receiver from the CustomEvent.
In Object: CustomEvent