ShotConnection
The hold a callback has on an event: keep it, and you can stop listening later.
Connect and Once on any signal give one. Disconnect() stops the calls, and Connected turns false then, after a Once callback has fired, and when the signal's instance is destroyed. Callbacks run in connect order, each in its own thread.
Example
-- Connect gives a ShotConnection: Disconnect stops its callback, and Connected says whether it still listens.
local title = Instance.new("StringValue")
local connection = title.Changed:Connect(function(text : string)
print("heard " .. text)
end)
title.Value = "Notes"
print("Connected: " .. tostring(connection.Connected))
connection:Disconnect()
title.Value = "Shop"
print("Connected after Disconnect: " .. tostring(connection.Connected))
-- destroying the instance cuts every connection to its signals
local other = title.Changed:Connect(function(text : string)
print("never printed: " .. text)
end)
title:Destroy()
print("Connected after Destroy: " .. tostring(other.Connected))heard Notes Connected: true Connected after Disconnect: false Connected after Destroy: false
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| Connected | boolean | True until Disconnect, until a Once callback has fired, or until the signal's instance is destroyed. |
Methods
| Name | Arguments | Returns | Description |
|---|---|---|---|
| Disconnect | () | () | Stops the calls to this callback; a second call does nothing. |
