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#
hooksignal(signal: RBXScriptSignal, callback: function): booleanParameters#
| Parameter | Type | Description |
|---|---|---|
signal | RBXScriptSignal | Engine signal, not a connection or local Signal facade. |
callback | function | Receives 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
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)