Hook a live function with a replacement (MUTATES STATE)
hook-functionIntercept and replace a live Roblox game function with custom code so all calls run your replacement; use it to log or rewrite arguments, spoof returns, or disable checks.
Instructions
WRITES LIVE GAME STATE. DANGER — MUTATES STATE PERSISTENTLY. Resolve a target function and replace it with your own function via hookfunction. After hooking, every call to the target — from anywhere in the game — runs your replacement instead. This is the core primitive for intercepting/altering game behavior: log or rewrite arguments, spoof return values, or no-op a check. The hook is GLOBAL and PERSISTS until undone, so it can easily destabilize the game or trip anticheat. The original function is captured and stored in getgenv().__mcp_hooks keyed by the target expression so you can recover it; you (or your replacement) can call the original, and you can fully undo the hook with restorefunction(target). Requires hookfunction. Pass confirm=true to proceed. Returns { Target, Hooked, OriginalStored } or { error }. Signature: { targetPath: string, hookFunction: string, confirm: boolean, threadContext: number? }. Phase: act; cost=medium; idempotency=contextual-write. Requires: active-client, resolved-target, explicit-mutation-approval. 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 |
|---|---|---|---|
| confirm | Yes | Must be true to actually install the hook (global, persistent mutation). When omitted or false, the tool refuses and changes nothing. | |
| targetPath | Yes | Luau expression resolving to the function to hook (the one whose calls you want to intercept), e.g. 'getsenv(game.Players.LocalPlayer.PlayerScripts.Main).validate' or 'getrawmetatable(game).__namecall'. Evaluated as `return <targetPath>`. | |
| hookFunction | Yes | Raw Luau expression that evaluates to the REPLACEMENT function. Typically a function literal, e.g. 'function(...) print("called", ...) return getgenv().__mcp_hooks[<target>](...) end' or 'newcclosure(function(...) return true end)'. To call the original from inside your hook, read it from getgenv().__mcp_hooks. Evaluated as `return <hookFunction>` and must resolve to a function. | |
| threadContext | No | Optional Roblox thread identity for this call; omit it to use the server default. |