The script-editing tools give an AI agent precise control over Luau source code. UseDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Chrrxs/robloxstudio-mcp/llms.txt
Use this file to discover all available pages before exploring further.
set_script_source to overwrite an entire script, the line-based tools (edit_script_lines, insert_script_lines, delete_script_lines) for targeted in-place edits that preserve unchanged code, and find_and_replace_in_scripts to apply the same change across every script in the place at once. Before using any of these tools, read the current source with get_script_source and the API docs for any engine classes involved with get_roblox_docs.
set_script_source
Replace the entire source of a script with new content. Use this when you need to write a script from scratch or completely rewrite an existing one. For partial edits — changing a few lines, inserting a block, or fixing a bug — use the line-editing tools below to avoid overwriting unrelated code.
Canonical path to a
LuaSourceContainer (e.g. game.ServerScriptService.RoundManager or game.ReplicatedStorage.Modules.Combat).The complete new source code to write. All existing content is replaced.
Which connected Studio place to target. Required when multiple places are connected; omit when only one is open. Use
get_connected_instances to list available IDs.edit_script_lines
Replace a specific block of text inside a script by matching exact content. The old_string must uniquely identify the text to replace within the script — if the same string appears more than once, the tool will reject the edit. When the text is ambiguous, use line_range to anchor the match to a specific line number.
Canonical path to a
LuaSourceContainer.The exact text to find and replace. Must appear exactly once in the script unless
line_range is also provided. Include enough surrounding context (e.g. the full function signature or block header) to make the match unique.The replacement text. Replaces the matched
old_string verbatim — indentation and whitespace are preserved exactly as supplied.Optional single-line anchor (e.g.
"42") where old_string begins. When provided, the uniqueness check is skipped and the tool requires old_string to match starting at exactly that line. Use this when the same string appears more than once in the file.Which connected Studio place to target. Required when multiple places are connected.
Uniqueness requirement: if
old_string appears more than once in the script and no line_range is given, the tool returns an error listing every line where it matched. Read the script with get_script_source to identify the correct line, then re-call with line_range set to that line number.insert_script_lines
Insert new lines of content into a script at any position. Pass afterLine: 0 to prepend content at the very beginning of the file.
Canonical path to a
LuaSourceContainer.The text to insert. The content is placed starting on the line immediately after
afterLine.The 1-based line number after which the new content is inserted. Pass
0 to insert at the very beginning of the file. Defaults to 0 when omitted.Which connected Studio place to target. Required when multiple places are connected.
delete_script_lines
Delete a specific range of lines from a script. The range is 1-indexed and inclusive. Open-ended ranges (e.g. "100-") are not accepted for deletion — you must specify both a start and an end line.
Canonical path to a
LuaSourceContainer.The lines to delete. Must be a closed range like
"10-20" (delete lines 10 through 20 inclusive) or a single line like "42" (delete only line 42). Open-ended ranges such as "100-" or "-50" are rejected.Which connected Studio place to target. Required when multiple places are connected.
find_and_replace_in_scripts
Find and replace text across every script in the game (or a scoped subtree) in a single call. Supports both literal text and Lua pattern matching, class-type filtering, and a dryRun mode that shows exactly what would change before you commit. Pair with grep_scripts when you only need to find matches — find_and_replace_in_scripts is for when you are ready to write.
The text or Lua pattern to search for across all script sources.
The replacement text. When
usePattern is true, Lua captures (%1, %2, etc.) are supported.Case-sensitive matching. Defaults to
false. Must be true when usePattern is true.Use Lua pattern matching instead of literal text search. Defaults to
false. Requires caseSensitive: true.Limit the scope to a subtree (e.g.
"game.ServerScriptService" to leave client scripts untouched).Only process scripts of a specific class:
"Script", "LocalScript", or "ModuleScript".When
true, return a preview of all changes that would be made without applying them. Defaults to false. Always run a dry-run first for broad replacements.Safety limit on the total number of replacements applied. Defaults to
1000. Reduce this value when testing a replacement on a large codebase to avoid unintended mass changes.Which connected Studio place to target. Required when multiple places are connected.
Example: find deprecated API usage and replace it safely
Roblox deprecatedgame.Players.LocalPlayer:GetMouse() in favour of UserInputService. The workflow below uses dryRun first to preview the scope of change, then applies it:
dryRun to apply: