Hook a metamethod on an object (MUTATES live state)
hook-metamethodReplace a metamethod on a live Roblox object with a custom hook to intercept every call routed through it. Requires confirm=true because it mutates state persistently.
Instructions
WRITES LIVE GAME STATE. DANGER — MUTATES STATE PERSISTENTLY. Resolve a Luau expression to an object and replace one of its metamethods (e.g. __namecall, __index, __newindex) with your own function via hookmetamethod. The hook stays active and INTERCEPTS EVERY call routed through that metamethod (for __namecall that is essentially every method call in the game), so a slow, throwing, or mis-behaving hook can hang or crash the client and is a strong anticheat signal. The original metamethod is stored in getgenv().__mcp_hooks under a descriptive key so you can later restore it with restorefunction or by re-hooking the saved original. Your hook function typically wraps the stored original (call it for unhandled cases) and should be a C closure (wrap it in newcclosure) to look native. Requires hookmetamethod. Because it mutates state you MUST pass confirm=true; otherwise the tool refuses and does nothing. Returns { Target, Method, Hooked, OriginalStored } or { error }. Signature: { objectPath: string, method: string, hookFunction: string, confirm: boolean, threadContext: number? }. Phase: act; cost=medium; idempotency=contextual-write. Requires: active-client, resolved-target, explicit-mutation-approval. Capabilities: getrawmetatable. Produces: structured-result. Verify with: is-function-hooked. Safety: MUTATING; changes persistent executor-side observer or hook state. On failure: inspect tool-schema for exact fields, defaults, constraints, and an invocation example.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method | Yes | The metamethod name to hook, e.g. '__namecall', '__index', '__newindex'. __namecall is the usual target for intercepting method calls (RemoteEvent:FireServer, etc.). | |
| confirm | Yes | Safety gate. Must be exactly true to apply the hook. If omitted or false the tool refuses and does nothing, because a persistent metamethod hook intercepts every call through it and can crash the game or trip anticheat. | |
| objectPath | Yes | Luau expression resolving to the object whose metamethod you want to hook, e.g. 'game', 'game.Players.LocalPlayer', or 'getgenv().SomeTable'. Evaluated as `return <objectPath>`. | |
| hookFunction | Yes | Raw Luau expression evaluating to the replacement function, MUST resolve to a function. Usually wrapped in newcclosure so it appears as a native C closure, e.g. 'newcclosure(function(self, ...) local m = getnamecallmethod(); if m == "FireServer" then return end; return getgenv().__mcp_hooks["..."](self, ...) end)'. Evaluated as `return <hookFunction>`. | |
| threadContext | No | Optional Roblox thread identity for this call; omit it to use the server default. |