Edit scripts
script_editEdit Luau scripts in Roblox Studio with batched literal find/replace, line ranges, or full rewrites. Batch applies only if every edit matches current source, preventing partial or stale changes.
Instructions
Edits Luau source through the Studio script editor. This is the tool to use for any change to existing code.
Every edit in one call is all-or-nothing: the whole batch is resolved against current source before anything is written, so if one edit cannot be applied nothing is. Batch related changes together, even across different scripts.
Each edit picks exactly one mode:
find/replace — literal text, not a pattern. Preferred: it survives line numbers shifting. Fails if the text is not unique, unless you set replaceAll, so include enough surrounding lines to pin it down.
startLine/endLine + replacement — for line ranges from script_read. Numbers refer to the file as you read it; several line edits to one script are applied bottom-up so they do not shift each other.
source — replaces the whole script. Only for small files or a rewrite; it discards anything the user changed since you read it.
Pass revision on every edit. script_read prints it as rev beside each file, and sending it back makes the write conditional: if the script changed since you read it the batch is refused with STALE_SCRIPT and nothing is written. Without it the edit is applied blind, which matters most for the two modes that cannot notice: a line range still applies cleanly to source somebody else moved, it just lands on the wrong lines, and source discards their work entirely. Another agent editing the same place, or the user typing in the editor, is enough.
Writes go through ScriptEditorService:UpdateSourceAsync, so an open editor tab updates in place and unsaved work is preserved. Undo for source changes is the script editor's own, per script — Ctrl+Z in a script tab reverts that script, not the whole batch.
target="live" edits the PUBLISHED place instead. It takes ONE edit, it replaces the whole source rather than finding and replacing, and there is no undo of any kind — so read the script with script_read target="live" first and send back the whole thing. Needs confirm: true.
It changes the SAVED place, not running servers: people already playing keep the old code until their server empties. Follow it with universe op="restart" to roll them over.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | live only: the script, e.g. "ServerScriptService.Main". | |
| edits | Yes | Edits to apply together as one undoable step. | |
| source | No | live only: the complete new source. | |
| target | No | 'studio' edits the open place. 'live' rewrites a script in the published place over Open Cloud — one file, whole source, no undo. | studio |
| confirm | No | Required for target="live". | |
| placeId | No | live only: omit to use `cloud place`. | |
| studioId | No | Target Studio; omit for the active one. | |
| universeId | No | live only: omit to use `cloud universe`. |