Toggle a metatable's read-only flag (MUTATES live state)
set-metatable-readonlyToggle a live metatable's read-only flag so you can edit or hook metamethods, then re-lock it to avoid anticheat tripwires or crashes.
Instructions
WRITES LIVE GAME STATE. DANGER — Resolve a Luau expression to a metatable (usually getrawmetatable(obj)) and flip its read-only flag via setreadonly. Most game metatables (e.g. getrawmetatable(game)) are locked read-only so __index/__namecall cannot be overwritten. Pass readonly=false to temporarily unlock a metatable so you can edit a metamethod (or run hook-metamethod), then call this again with readonly=true to RE-LOCK it — leaving a core metatable writable is a classic anticheat tripwire and can crash or destabilize the game. This changes the live runtime; it does not create a copy. Requires setreadonly. Because it mutates state you MUST pass confirm=true; otherwise the tool refuses and does nothing. Returns { Target, ReadOnly, ok } or { error }. Signature: { targetPath: string, readonly: boolean, confirm: boolean, threadContext: number? }. Phase: act; cost=medium; idempotency=idempotent-write. Requires: active-client, resolved-target, explicit-mutation-approval. Capabilities: getrawmetatable. Produces: structured-observation, operation-receipt. Verify with: assert-state. Safety: MUTATING; writes live game/client state. On failure: inspect tool-schema for exact fields, defaults, constraints, and an invocation example.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| confirm | Yes | Safety gate. Must be exactly true to apply the change. If omitted or false the tool refuses and does nothing, because toggling read-only on a live metatable can destabilize the game or trip anticheat. | |
| readonly | Yes | The new read-only state. false = unlock the metatable so its metamethods can be edited/hooked; true = re-lock it. Always re-lock when you are done to avoid leaving the game in an unprotected, anticheat-suspicious state. | |
| targetPath | Yes | Luau expression resolving to the metatable (a table) whose read-only flag you want to change, e.g. 'getrawmetatable(game)', 'getrawmetatable(game.Players.LocalPlayer)', or 'getgenv().SomeLockedTable'. Evaluated as `return <targetPath>`. Should resolve to a table — non-tables will error. | |
| threadContext | No | Optional Roblox thread identity for this call; omit it to use the server default. |