Edit scripts
script_editEdit existing Luau code in Roblox Studio's script editor. Apply batched, all-or-nothing changes with revision checks so stale or conflicting writes are refused.
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. Line-range and source edits REQUIRE it (NEEDS_REVISION otherwise), because they cannot notice a change: a line range lands on whatever moved into those lines, and source discards the other side's work. Another agent editing the same place, or the user typing in the editor, is enough. find/replace works without it.
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, with its rev as revision so the write is refused if someone published in between. 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 | No | Edits to apply together as one undoable step. Required unless target is "live". The result carries each script's new `rev`, so a follow-up edit needs no re-read. | |
| 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`. | |
| revision | No | live only, required: the `rev` `script_read target="live"` printed. The write is refused if the published script changed since. | |
| studioId | No | Target Studio; omit for the active one. | |
| universeId | No | live only: omit to use `cloud universe`. |