Source: Roblox Creator Hub · CC BY 4.0 · View source · Code samples: MIT Imported 2026-10-03. Formatting adapted for this site.
ScriptEditorService
Inherits from: Instance → Object
This service is used for interacting with ScriptDocument instances. It provides methods to open, find, and list script documents that represent scripts currently open in the Studio Script Editor. It also enables plugins to register custom callbacks for autocomplete and script analysis, and fires events when script documents are opened, closed, or changed.
This service is only available in Studio plugins and the command bar (Plugin security level).
Inherits from: Instance
Memory category: Instances
Tags: NotCreatable, Service, NotReplicated
Methods
| Name | Type / Returns | Description |
|---|---|---|
| ScriptEditorService:DeregisterAutocompleteCallback | () | Removes a previously registered callback with the name name. |
| ScriptEditorService:DeregisterScriptAnalysisCallback | () | Removes a previously registered callback with the name name. |
| ScriptEditorService:FindScriptDocument | ScriptDocument | Returns the open ScriptDocument corresponding to the given LuaSourceContainer, or nil if the given script is not open. |
| ScriptEditorService:GetEditorSource | string | Returns the edit-time source for the given script. |
| ScriptEditorService:GetScriptDocuments | List | Returns an array of the currently open script documents, including the command bar. |
| ScriptEditorService:OpenScriptDocumentAsync | Tuple | Requests that a Script Editor open the specified script. Returns (true, nil) if the request succeeds. Returns (false, string) if the request fails, with a string that describes the problem. |
| ScriptEditorService:RegisterAutocompleteCallback | () | Registers an autocomplete callback callbackFunction named name with priority priority. |
| ScriptEditorService:RegisterScriptAnalysisCallback | () | Registers a Script Analysis callback callbackFunction named name with priority. |
| ScriptEditorService:UpdateSourceAsync | () | Generates new content from the old script and updates the script editor if it's open, or the Script instance if the script editor is closed. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance:AddTag | () | Applies a tag to the instance. |
| Instance:children | Instances | Returns an array of the object's children. |
| Instance:ClearAllChildren | () | This method destroys all of an instance's children. |
| Instance:Clone | Instance | Create a copy of an instance and all its descendants, ignoring instances that are not Archivable. |
| Instance:clone | Instance | |
| Instance:Destroy | () | Sets the Instance.Parent property to nil, locks the Instance.Parent property, disconnects all connections, and calls Destroy() on all children. |
| Instance:destroy | () | |
| Instance:FindFirstAncestor | Instance? | Returns the first ancestor of the Instance whose Instance.Name is equal to the given name. |
| Instance:FindFirstAncestorOfClass | Instance? | Returns the first ancestor of the Instance whose Object.ClassName is equal to the given className. |
| Instance:FindFirstAncestorWhichIsA | Instance? | Returns the first ancestor of the Instance for whom Object:IsA() returns true for the given className. |
| Instance:FindFirstChild | Instance? | Returns the first child of the Instance found with the given name. |
| Instance:findFirstChild | Instance | |
| Instance:FindFirstChildOfClass | Instance? | Returns the first child of the Instance whose ClassName is equal to the given class name. |
| Instance:FindFirstChildWhichIsA | Instance? | Returns the first child of the Instance for whom Object:IsA() returns true for the given className. |
| Instance:FindFirstDescendant | Instance? | Returns the first descendant found with the given Instance.Name. |
| Instance:GetActor | Actor? | Returns the Actor associated with the Instance, if any. |
| Instance:GetAttribute | Variant | Returns the value which has been assigned to the given attribute name. |
| Instance:GetAttributeChangedSignal | RBXScriptSignal | Returns an event that fires when the given attribute changes. |
| Instance:GetAttributes | Dictionary | Returns a dictionary of the instance's attributes. |
| Instance:GetChildren | Instances | Returns an array containing all of the instance's children. |
| Instance:getChildren | Instances | |
| Instance:GetDebugId | string | Returns a coded string of the debug ID used internally by Roblox. |
| Instance:GetDescendants | Instances | Returns an array containing all of the descendants of the instance. |
| Instance:GetFullName | string | Returns a string describing the instance's ancestry. |
| Instance:GetStyled | Variant | Returns the styled or explicitly modified value of the specified property, or else the default property value if it hasn't been styled/modified. |
| Instance:GetStyledPropertyChangedSignal | RBXScriptSignal | Returns an event that fires when the given style property changes on the instance. |
| Instance:GetTags | Array | Gets an array of all tags applied to the instance. |
| Instance:HasTag | boolean | Check whether the instance has a given tag. |
| Instance:IsAncestorOf | boolean | Returns true if an Instance is an ancestor of the given descendant. |
| Instance:IsDescendantOf | boolean | Returns true if an Instance is a descendant of the given ancestor. |
| Instance:isDescendantOf | boolean | |
| Instance:IsPropertyModified | boolean | Returns true if the value stored in the specified property is not equal to the code-instantiated default. |
| Instance:QueryDescendants | Instances | Returns an array containing all descendants of the instance that match the selector string. |
| Instance:Remove | () | Sets the object's Parent to nil, and does the same for all its descendants. |
| Instance:remove | () | |
| Instance:RemoveTag | () | Removes a tag from the instance. |
| Instance:ResetPropertyToDefault | () | Resets a property to its default value. |
| Instance:SetAttribute | () | Sets the attribute with the given name to the given value. |
| Instance:WaitForChild | Instance | Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object:GetPropertyChangedSignal | RBXScriptSignal | Get an event that fires when a given property of the object changes. |
| Object:IsA | boolean | Returns true if an object's class matches or inherits from a given class. |
| Object:isA | boolean |
ScriptEditorService:DeregisterAutocompleteCallback
Removes a previously registered autocomplete callback with the name name. The callback must have been registered with ScriptEditorService:RegisterAutocompleteCallback(). Throws an error if no callback with the given name is currently registered.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | string | The identifier that was used when registering the callback with ScriptEditorService:RegisterAutocompleteCallback(). |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
Code samples: View on Creator Hub (ScriptEditorService-DeregisterAutocompleteCallback).
ScriptEditorService:DeregisterScriptAnalysisCallback
Removes a previously registered Script Analysis callback with the name name. The callback must have been registered with ScriptEditorService:RegisterScriptAnalysisCallback(). Throws an error if no callback with the given name is currently registered.
After the callback is removed, Script Analysis automatically reruns on all open scripts to update diagnostics.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | string | The identifier that was used when registering the callback with ScriptEditorService:RegisterScriptAnalysisCallback(). |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
Code samples: View on Creator Hub (ScriptEditorService-DeregisterScriptAnalysisCallback).
ScriptEditorService:FindScriptDocument
Returns the open ScriptDocument corresponding to the given LuaSourceContainer, or nil if the given script is not open.
A ScriptDocument only exists while the script has an open tab in the Script Editor. If the script's editor tab is closed, this method returns nil even if the script instance still exists in the DataModel.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| script | LuaSourceContainer | The LuaSourceContainer (such as a Script, LocalScript, or ModuleScript) to find the open document for. |
Returns
| Type | Description |
|---|---|
| ScriptDocument | The open ScriptDocument corresponding to the given script, or nil if the script is not currently open in the Script Editor. |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
Code samples: View on Creator Hub (ScriptDocument-CloseAsync, ScriptDocument-ViewportChanged).
ScriptEditorService:GetEditorSource
Returns the edit-time source for the given script.
If the script is open in the Script Editor, this method returns the text currently being displayed in the editor. If the script is not open in the editor, the method returns the text that the editor would display if it's opened. The edit-time source is not always be consistent with the Script.Source property.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| script | LuaSourceContainer | The LuaSourceContainer to retrieve the edit-time source text for. |
Returns
| Type | Description |
|---|---|
| string | The edit-time source text of the script as a string. |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
ScriptEditorService:GetScriptDocuments
Returns an array of the currently open script documents, including the command bar. Each entry is a ScriptDocument representing one open editor tab. The command bar's document can be identified with ScriptDocument:IsCommandBar() if you need to exclude it.
Returns
| Type | Description |
|---|---|
| List | An array of ScriptDocument objects representing all currently open editor tabs, including the command bar. |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
Code samples: View on Creator Hub (ScriptEditorService-GetScriptDocuments).
ScriptEditorService:OpenScriptDocumentAsync
Requests that a Script Editor open the specified script. Returns (true, nil) if the request succeeds. Returns (false, string) if the request fails, with a string that describes the problem.
If the script is already open, this function succeeds and switches tabs to the associated editor.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| script | LuaSourceContainer | The LuaSourceContainer to open in the Script Editor. | |
| options | Dictionary | nil | A dictionary that supports the following options: - Temporary — Boolean. Whether to open the script in a preview tab. Default is false. - HighlightRange — A nested dictionary containing a line and character range to highlight in the editor. Example: HighlightRange = { Start = { Line = 10, Character = 1 }, End = { Line = 15, Character = 20 }}. |
Returns
| Type | Description |
|---|---|
| Tuple | A tuple where the first value is a boolean indicating success and the second is nil on success or a string describing the problem on failure. |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | PluginSecurity |
| thread safety | Unsafe |
Code samples: View on Creator Hub (ScriptEditorService-OpenScriptDocumentAsync).
ScriptEditorService:RegisterAutocompleteCallback
Registers an autocomplete callback callbackFunction named name with priority priority.
When the Script Editor invokes autocomplete, all registered autocomplete callbacks call in order of ascending priority with the autocomplete request and response. Multiple callbacks may share a priority, but then their calling order is unpredictable. Each callback is intended to return a response table with the same format as the response input table. Callbacks shouldn't yield. The first callback invoked receives the internal autocomplete's response as its response table, and subsequent callbacks receive the previous callback's output as their response table. Callbacks may either modify the passed table or return a new table of the same format.
The callbackFunction must have the following type: (Request: table, Response: table) -> table
The Request table has the following format:
type Request = {
position: {
line: number,
character: number
},
textDocument: {
document: ScriptDocument?,
script: LuaSourceContainer?
}
} positionis the one-indexed cursor position where you are autocompleting.textDocument.documentis the openScriptDocumentyou are completing in, if it exists.textDocument.scriptis theLuaSourceContaineryou are completing in, if it exists.
If both textDocument.document and textDocument.script are present, then they correspond to each other: req.textDocument.document:GetScript() == req.textDocument.script
The Response table has the following format:
type Response = {
items: {
{
label: string, -- The label
kind: Enum.CompletionItemKind?,
tags: {Enum.CompletionItemTag}?,
detail: string?,
documentation: {
value: string,
}?,
overloads: number?,
learnMoreLink: string?,
codeSample: string?,
preselect: boolean?,
textEdit: {
newText: string,
insert: { start: { line: number, character: number }, ["end"]: { line: number, character: number } },
replace: { start: { line: number, character: number }, ["end"]: { line: number, character: number } },
}?
}
}
} Response.itemsis an array of the completion items. The order of this array is insignificant, and it resorts in the editor as the user types.Response.items[n].labelis the label of the item which display in the autocomplete menu.Response.items[n].kindspecifies what type of autocomplete item this is. Primarily this controls the icon given to the item in the editor. Not all kinds have a unique icon. If not specified, the editor uses the "Text" icon. Unsupported kinds default to displaying the "Property" icon.Response.items[n].tagsspecifies an array of tags describing this completion item. See theCompletionItemTagfor details on their function.Response.items[n].detailsspecifies a string describing details about the completion item. For default items, this is a string representation of their type. Note that, in order for the documentation widget to display,documentationmust be present, butdocumentation.valuemay be empty.Response.items[n].documentationspecifies the main body of the documentation in itsvaluefield.documentationis present, even if value is empty, so the documentation window displays if either details or overloads are specified.Response.items[n].overloadsspecifies the number of overloads of a function autocompletion.Response.items[n].learnMoreLinklinks to a relevant page on the creator docs. This URL must be ahttpsrequest to create.roblox.com; no other URLs display in the editor.Response.items[n].codeSamplespecifies a sample use of the completion item.documentationmust be non-empty to display this field.Response.items[n].preselectIf true, the editor sorts this completion item ahead of all others and selects it for the user by default. No effect if false or missing.Response.items[n].textEditIf present, accepting the completion applies this text edit - inserting or replacing the span between the positions start and end with newText.
If a callback returns a malformed result or encounters an error, the editor discards the modified Response table and uses the built-in autocomplete result list.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | string | A unique identifier for this callback, used to deregister it later with ScriptEditorService:DeregisterAutocompleteCallback(). | |
| priority | int | The invocation order among registered callbacks; lower values run first. | |
| callbackFunction | Function | The function invoked during autocomplete with the signature (Request: table, Response: table) -> table. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
Code samples: View on Creator Hub (ScriptEditorService-RegisterAutocompleteCallback).
ScriptEditorService:RegisterScriptAnalysisCallback
Registers a Script Analysis callback callbackFunction named name with priority. When Script Analysis in Studio runs, all registered callbacks call in order of ascending priority. Each callback is intended to return a response table matching the format specified below. Callbacks should not yield.
The request table has the following format, where script is the LuaSourceContainer that is going to be analyzed.
type Request = {
script: LuaSourceContainer?
} The response table has the following format, where diagnostics is an array of diagnostic tables. Each diagnostic table has the entries listed below.
type Response = {
diagnostics: {
{
range: {
start: {
line: number,
character: number,
},
["end"]: {
line: number,
character: number,
}
},
code: string?,
message: string,
severity: Enum.Severity?,
codeDescription: { href: string }?
}
}
} rangerepresents a text range that should be highlighted by the linter, providing what line/character to start highlighting and what line/character to stop highlighting.codeis a label for the message.messageis a warning message to be displayed for the line. This will also appear on a tooltip when the user hovers their cursor over the line in the Script Editor.severityis aSeverityvalue for the diagnostics. This determines how the diagnostic is categorized in the Script Analysis tool in Studio, as well as how text is highlighted in the Script Editor.codeDescriptionlinks to a relevant page on the creator docs. This URL must be anhttpsrequest tocreate.roblox.com; no other URLs display in the editor.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | string | A unique identifier for this callback, used to deregister it later with ScriptEditorService:DeregisterScriptAnalysisCallback(). | |
| priority | int | The invocation order among registered callbacks; lower values run first. | |
| callbackFunction | Function | The function invoked during Script Analysis with the signature (Request: table) -> table, returning a response containing diagnostics. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| security | PluginSecurity |
| thread safety | Unsafe |
Code samples: View on Creator Hub (ScriptEditorService-RegisterScriptAnalysisCallback).
ScriptEditorService:UpdateSourceAsync
Returns the edit-time Script.Source for the given script.
This function calls the passed callback using the old contents of the script to calculate the new contents of the script.
If the script is open in the Script Editor, then it issues a request to the editor to update its source. The editor may reject this update if the Script.Source property was out of date with the user's version of the script when this function was called, in which case the callback will be re-invoked and the attempt will be repeated.
The callback may not yield. If the callback returns nil, the operation is cancelled. This function yields until the operation is cancelled or succeeds.
If the script is not open in the editor, the new content updates to the script source, which is the text the editor would display if it is opened.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| script | LuaSourceContainer | Script instance to be updated. | |
| callback | Function | The function to return new script content. |
Returns
| Type | Description |
|---|---|
| () |
| Field | Value |
|---|---|
| tags | ["Yields"] |
| security | PluginSecurity |
| thread safety | Unsafe |
Code samples: View on Creator Hub (ScriptEditorService-UpdateSourceAsync).
Events
| Name | Type / Returns | Description |
|---|---|---|
| ScriptEditorService.TextDocumentDidChange | Fires just after a ScriptDocument changes. | |
| ScriptEditorService.TextDocumentDidClose | Fires just before a ScriptDocument object is destroyed, which happens right after the script editor closes. | |
| ScriptEditorService.TextDocumentDidOpen | Fires just after a ScriptDocument object is created and parented to the service, which happens right after the script editor opens. |
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance.AncestryChanged | Fires when the Instance.Parent property of this object or one of its ancestors is changed. | |
| Instance.AttributeChanged | Fires whenever an attribute is changed on the Instance. | |
| Instance.ChildAdded | Fires after an object is parented to this Instance. | |
| Instance.childAdded | ||
| Instance.ChildRemoved | Fires after a child is removed from this Instance. | |
| Instance.DescendantAdded | Fires after a descendant is added to the Instance. | |
| Instance.DescendantRemoving | Fires immediately before a descendant of the Instance is removed. | |
| Instance.Destroying | Fires immediately before (or is deferred until after) the instance is destroyed via Instance:Destroy(). | |
| Instance.StyledPropertiesChanged | Fires whenever any style property is changed on the instance, including when a property is set to nil. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object.Changed | Fires immediately after a property of the object changes, with some limitations. |
ScriptEditorService.TextDocumentDidChange
Fires just after a ScriptDocument changes. The textChanged is an array of change structures of the format:
{ range : { start : { line : number, character : number }, end : { line : number, character : number } }, text: string }
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| document | ScriptDocument | The ScriptDocument that changed. | |
| changesArray | Variant | An array of change structures, each describing a range that was replaced and the new text. |
| Field | Value |
|---|---|
| security | PluginSecurity |
Code samples: View on Creator Hub (ScriptEditorService-TextDocumentDidChange).
ScriptEditorService.TextDocumentDidClose
Fires just before a ScriptDocument object is destroyed, which happens right after the script editor closes. After this event fires, the ScriptDocument enters a "Closed" state, and trying to call its methods throws an error. ScriptDocument objects aren't reusable, even if the script editor reopens the same script.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| oldDocument | ScriptDocument | The ScriptDocument that is about to be destroyed. |
| Field | Value |
|---|---|
| security | PluginSecurity |
Code samples: View on Creator Hub (ScriptEditorService-TextDocumentDidClose).
ScriptEditorService.TextDocumentDidOpen
Fires just after a ScriptDocument object is created and parented to the service, which happens right after the script editor opens. The ScriptDocument passed to the handler is fully initialized and ready to read or modify. This event also fires for the command bar document.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| newDocument | ScriptDocument | The newly created ScriptDocument representing the opened editor tab. |
| Field | Value |
|---|---|
| security | PluginSecurity |
Code samples: View on Creator Hub (ScriptEditorService-TextDocumentDidOpen).
Properties
Inherited from Instance
| Name | Type / Returns | Description |
|---|---|---|
| Instance.Archivable | boolean | Determines if an Instance and its descendants can be cloned using Instance:Clone(), and can be saved/published. |
| Instance.archivable | boolean | |
| Instance.Capabilities | SecurityCapabilities | The set of capabilities allowed to be used for scripts inside this container. |
| Instance.IsInSandbox | boolean | Indicates whether the instance is inside a sandboxed container. |
| Instance.Name | string | A non-unique identifier of the Instance. |
| Instance.Parent | Instance | Determines the hierarchical parent of the Instance. |
| Instance.PredictionMode | PredictionMode | Reflects the client-side prediction mode applied to the instance under server-authoritative physics. |
| Instance.RobloxLocked | boolean | A deprecated property that used to protect CoreGui objects. |
| Instance.Sandboxed | boolean | When enabled, the instance can only access abilities in its Capabilities list. |
| Instance.UniqueId | UniqueId | A unique identifier for the instance. |
Inherited from Object
| Name | Type / Returns | Description |
|---|---|---|
| Object.ClassName | string | A read-only string representing the class this Object belongs to. |
| Object.className | string |