Overview
Replace specific lines in a Roblox script without rewriting the entire source. Provides precise, line-level editing for efficient script modifications.Line numbers are 1-indexed and ranges are inclusive. Always use the
numberedSource field from get_script_source to identify correct line numbers.Parameters
Roblox instance path to the script using dot notationExamples:
game.ServerScriptService.MainScriptgame.StarterPlayer.StarterPlayerScripts.LocalScriptgame.ReplicatedStorage.Modules.DataManager
First line to replace (1-indexed)Get from
numberedSource field of get_script_sourceLast line to replace (inclusive)Get from
numberedSource field of get_script_sourceNew content to replace the specified lines
- Can be single line or multiple lines (separated by
\n) - Preserves indentation exactly as provided
- Must be valid Lua syntax
Response
Whether the operation completed successfully
Status message describing the operation
Number of lines removed (endLine - startLine + 1)
Number of lines added
Total lines in script after edit
Usage Examples
Replace Single Line
Replace Function Body
Before (lines 45-47):Replace Multiple Lines
Before (lines 20-25):Best Practices
Always Read Before Editing
Always Read Before Editing
Step 1: Call Step 2: Find target lines in Step 3: Use exact line numbers from numberedSource:
get_script_source to get current line numbersnumberedSource:Preserve Indentation
Preserve Indentation
Match the indentation of surrounding code:When editing line 19 (inside if statement), use 12 spaces:
Handle Multi-Line Replacements
Handle Multi-Line Replacements
Use This replaces line 10 with 3 new lines.
\n to separate lines in newContent:Line Range is Inclusive
Line Range is Inclusive
startLine to endLine includes both endpoints:startLine: 5, endLine: 5→ replaces line 5 onlystartLine: 5, endLine: 7→ replaces lines 5, 6, and 7startLine: 5, endLine: 10→ replaces 6 lines total
Validate Syntax After Editing
Validate Syntax After Editing
After making edits, verify the script still has valid syntax:
Common Patterns
Update Function Logic
Replace function body
Fix Bug in Specific Lines
Fix off-by-one error
Update Variable Declaration
Change variable initialization
Related Tools
get_script_source
Read script with line numbers
set_script_source
Replace entire script
insert_script_lines
Insert new lines
delete_script_lines
Delete line ranges
Error Handling
Complete Workflow Example
Step 1: Read current source
Step 2: Analyze numberedSource
Step 3: Edit specific
Step 4: Result