Yuari
Documentation
Docs/Closures/hooksignal

hooksignal(signal, hook)

Replaces every Lua connection callback on a signal with a dispatcher that calls your hook.

Syntax

hooksignal(signal: RBXScriptSignal, hook: function) -> boolean

Parameters

ParameterTypeDescription
signalRBXScriptSignalSignal to hook.
hookfunctionReceives (connectionInfo, ...originalArgs) and returns whether the original callback should run.

Returns

TypeDescription
booleantrue when at least one connection callback was replaced.

Description

Implementation changed: the executor now rewrites the connection's function reference in the engine slot wrapper. The stored registry reference is replaced with a dispatcher closure and the previous reference is kept for restoresignal.

The dispatcher calls hook(connectionInfo, ...args). Returning a falsy value blocks the original callback; returning true calls the original callback with the original arguments. Errors raised by the hook propagate to the signal fire.

Foreign-state connections and C callbacks are skipped. Hooking an already hooked signal restores the previous replacement first.

Example

local value = Instance.new("NumberValue")
value.Changed:Connect(function() print("fired") end)
hooksignal(value.Changed, function(info, newValue)
    print("hooked", newValue)
    return false -- block the original callback
end)
value.Value = 1

Notes

  • Use restoresignal to put the original callbacks back.
  • Returns false when the signal has no Lua callbacks to replace.