Skip to content
Functions & closuresReference

hooksignal

Represents interception of signal callbacks.

Details#

Hooks eligible existing local Luau handlers of an RBXScriptSignal. The callback receives a metadata table followed by event arguments. Metadata may expose Connection, Function and a zero-based Index. Return true followed by the arguments to pass to the saved original handler; a false/nil first result suppresses that handler. Returning true alone forwards zero arguments. Foreign-state and native handlers are skipped; a signal with no eligible handlers returns false. New subscriptions are not automatically covered.

Signature#

Luau
hooksignal(signal: RBXScriptSignal, callback: function): boolean

Parameters#

ParameterTypeDescription
signalRBXScriptSignalEngine signal, not a connection or local Signal facade.
callbackfunctionReceives metadata and event arguments; returns forward boolean and replacement arguments.

Returns#

true if at least one eligible local Luau handler was hooked; false if none was found.

Examples#

Example

Luau
local event = Instance.new("BindableEvent")
local connection = event.Event:Connect(function(value) print(value) end)
local hooked = hooksignal(event.Event, function(metadata, value)
    print("Handler index:", metadata.Index)
    return true, value -- forward the argument to the saved handler
end)
print("Hook installed:", hooked)
event:Fire("local event")
task.defer(function()
    restoresignal(event.Event)
    connection:Disconnect()
    event:Destroy()
end)