AcediaDocumentation

hooksignal

Routes a signal's executor-owned connections through a callback.

Every Lua connection this VM owns on the signal is replaced with a wrapper. Engine connections, connections belonging to another VM and Wait slots are left alone, so a signal with no connection of ours is a no-op rather than an error.

The hook is called as hook(info, ...) with the fired arguments after info. Returning true lets the original callback run with those same arguments; any other return blocks it. An error raised inside the hook propagates to the firing code.

hooksignal(signal: RBXScriptSignal, hook: (info: table, ...any) -> boolean?): ()

Parameters

ParameterTypeDescription
signalRBXScriptSignalSignal whose connections are wrapped.
hookfunctionCallback receiving the info table and the fired arguments.

Info fields

FieldTypeDescription
FunctionfunctionThe original connected callback.
Connectiontable?The matching row from getconnections, when one was found.
IndexnumberOne-based position of that row, or 0 when no row matched.

Example

local bindable = Instance.new("BindableEvent")
bindable.Event:Connect(function(value) print("original", value) end)
hooksignal(bindable.Event, function(info, value)
    print("hook", value)
    return true
end)
bindable:Fire("example")

Example output

hook example
original example

See issignalhooked and restoresignal.

On this page