Intercepts signal, so that every time it fires, your callback runs once per Lua connection on it, before that connection does. The callback receives information about the connection plus the arguments the signal was fired with, and decides whether the real connection runs. Return a truthy value to let the connection run; return false or nil to suppress it.

Parameters

RBXScriptSignal
required
The signal to intercept. It must be a real RBXScriptSignal backed by an engine event descriptor.
function
required
Called as callback(info, ...) for each Lua connection, where ... is the arguments the signal fired with.

Returns

boolean
true once the hook is installed.

The info table

RBXScriptConnection
The connection that is about to run.
function
The connected function. Absent for a connection that has no readable function, such as one waiting in Wait.
string
The event’s name, e.g. "Changed".
userdata
A light userdata identifying the script context the connection belongs to. Useful only for telling contexts apart.

Behavior

  • Only the first return value is read, and only for its truthiness. You cannot rewrite the arguments the connection receives.
  • Do not yield. The callback runs synchronously inside the engine’s fire path. Yielding from it fails the call, which is treated as “run the original”.
  • Errors let the connection run. If your callback raises, the error is logged and the connection proceeds, so a mistake in a hook cannot silently swallow game events.
  • No re-entry. If handling a fire causes the same hook to fire again, the nested fire runs its connections normally instead of calling your callback again.
  • Lua connections only. Engine-side connections are not routed through the callback.

Example

Errors