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 and disconnectShotScript
-- 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))
What it printedOutput
heard Notes
Connected: true
Connected after Disconnect: false
Connected after Destroy: false

Properties

NameTypeDefaultDescription
ConnectedbooleanTrue until Disconnect, until a Once callback has fired, or until the signal's instance is destroyed.

Methods

NameArgumentsReturnsDescription
Disconnect()()Stops the calls to this callback; a second call does nothing.