Volt

VoltSignal:Connect

Connects a handler function to the signal.

Syntax

VoltSignal:Connect(f: function) -> VoltConnection

Parameters

ParameterTypeDescription
ffunctionThe handler function to call when the signal fires

Returns

TypeDescription
VoltConnectionA connection object that can be used to disconnect

Description

VoltSignal:Connect registers a function to be called whenever the signal is fired. The function will receive any arguments passed to Fire. Returns a VoltConnection that can be used to disconnect the handler.

Example

local signal = VoltSignal.new()

-- Connect a handler
local connection = signal:Connect(function(message)
    print("Received:", message)
end)

-- Fire the signal
signal:Fire("Hello, World!")
-- Output: Received: Hello, World!

-- Disconnect when done
connection:Disconnect()

Multiple Connections

local signal = VoltSignal.new()

signal:Connect(function(value)
    print("Handler 1:", value)
end)

signal:Connect(function(value)
    print("Handler 2:", value * 2)
end)

signal:Fire(10)
-- Output:
-- Handler 1: 10
-- Handler 2: 20

On this page