16 min read

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

NameType / ReturnsDescription
ScriptEditorService:DeregisterAutocompleteCallback()Removes a previously registered callback with the name name.
ScriptEditorService:DeregisterScriptAnalysisCallback()Removes a previously registered callback with the name name.
ScriptEditorService:FindScriptDocumentScriptDocumentReturns the open ScriptDocument corresponding to the given LuaSourceContainer, or nil if the given script is not open.
ScriptEditorService:GetEditorSourcestringReturns the edit-time source for the given script.
ScriptEditorService:GetScriptDocumentsListReturns an array of the currently open script documents, including the command bar.
ScriptEditorService:OpenScriptDocumentAsyncTupleRequests 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

NameType / ReturnsDescription
Instance:AddTag()Applies a tag to the instance.
Instance:childrenInstancesReturns an array of the object's children.
Instance:ClearAllChildren()This method destroys all of an instance's children.
Instance:CloneInstanceCreate a copy of an instance and all its descendants, ignoring instances that are not Archivable.
Instance:cloneInstance
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:FindFirstAncestorInstance?Returns the first ancestor of the Instance whose Instance.Name is equal to the given name.
Instance:FindFirstAncestorOfClassInstance?Returns the first ancestor of the Instance whose Object.ClassName is equal to the given className.
Instance:FindFirstAncestorWhichIsAInstance?Returns the first ancestor of the Instance for whom Object:IsA() returns true for the given className.
Instance:FindFirstChildInstance?Returns the first child of the Instance found with the given name.
Instance:findFirstChildInstance
Instance:FindFirstChildOfClassInstance?Returns the first child of the Instance whose ClassName is equal to the given class name.
Instance:FindFirstChildWhichIsAInstance?Returns the first child of the Instance for whom Object:IsA() returns true for the given className.
Instance:FindFirstDescendantInstance?Returns the first descendant found with the given Instance.Name.
Instance:GetActorActor?Returns the Actor associated with the Instance, if any.
Instance:GetAttributeVariantReturns the value which has been assigned to the given attribute name.
Instance:GetAttributeChangedSignalRBXScriptSignalReturns an event that fires when the given attribute changes.
Instance:GetAttributesDictionaryReturns a dictionary of the instance's attributes.
Instance:GetChildrenInstancesReturns an array containing all of the instance's children.
Instance:getChildrenInstances
Instance:GetDebugIdstringReturns a coded string of the debug ID used internally by Roblox.
Instance:GetDescendantsInstancesReturns an array containing all of the descendants of the instance.
Instance:GetFullNamestringReturns a string describing the instance's ancestry.
Instance:GetStyledVariantReturns the styled or explicitly modified value of the specified property, or else the default property value if it hasn't been styled/modified.
Instance:GetStyledPropertyChangedSignalRBXScriptSignalReturns an event that fires when the given style property changes on the instance.
Instance:GetTagsArrayGets an array of all tags applied to the instance.
Instance:HasTagbooleanCheck whether the instance has a given tag.
Instance:IsAncestorOfbooleanReturns true if an Instance is an ancestor of the given descendant.
Instance:IsDescendantOfbooleanReturns true if an Instance is a descendant of the given ancestor.
Instance:isDescendantOfboolean
Instance:IsPropertyModifiedbooleanReturns true if the value stored in the specified property is not equal to the code-instantiated default.
Instance:QueryDescendantsInstancesReturns 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:WaitForChildInstanceReturns 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

NameType / ReturnsDescription
Object:GetPropertyChangedSignalRBXScriptSignalGet an event that fires when a given property of the object changes.
Object:IsAbooleanReturns true if an object's class matches or inherits from a given class.
Object:isAboolean

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

NameTypeDefaultDescription
namestringThe identifier that was used when registering the callback with ScriptEditorService:RegisterAutocompleteCallback().

Returns

TypeDescription
()
FieldValue
securityPluginSecurity
thread safetyUnsafe

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

NameTypeDefaultDescription
namestringThe identifier that was used when registering the callback with ScriptEditorService:RegisterScriptAnalysisCallback().

Returns

TypeDescription
()
FieldValue
securityPluginSecurity
thread safetyUnsafe

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

NameTypeDefaultDescription
scriptLuaSourceContainerThe LuaSourceContainer (such as a Script, LocalScript, or ModuleScript) to find the open document for.

Returns

TypeDescription
ScriptDocumentThe open ScriptDocument corresponding to the given script, or nil if the script is not currently open in the Script Editor.
FieldValue
securityPluginSecurity
thread safetyUnsafe

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

NameTypeDefaultDescription
scriptLuaSourceContainerThe LuaSourceContainer to retrieve the edit-time source text for.

Returns

TypeDescription
stringThe edit-time source text of the script as a string.
FieldValue
securityPluginSecurity
thread safetyUnsafe

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

TypeDescription
ListAn array of ScriptDocument objects representing all currently open editor tabs, including the command bar.
FieldValue
securityPluginSecurity
thread safetyUnsafe

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

NameTypeDefaultDescription
scriptLuaSourceContainerThe LuaSourceContainer to open in the Script Editor.
optionsDictionarynilA 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

TypeDescription
TupleA 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.
FieldValue
tags["Yields"]
securityPluginSecurity
thread safetyUnsafe

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?
  }
}

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 } },
      }?
    }
  }
}

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

NameTypeDefaultDescription
namestringA unique identifier for this callback, used to deregister it later with ScriptEditorService:DeregisterAutocompleteCallback().
priorityintThe invocation order among registered callbacks; lower values run first.
callbackFunctionFunctionThe function invoked during autocomplete with the signature (Request: table, Response: table) -> table.

Returns

TypeDescription
()
FieldValue
securityPluginSecurity
thread safetyUnsafe

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 }?
    }
  }
}

Parameters

NameTypeDefaultDescription
namestringA unique identifier for this callback, used to deregister it later with ScriptEditorService:DeregisterScriptAnalysisCallback().
priorityintThe invocation order among registered callbacks; lower values run first.
callbackFunctionFunctionThe function invoked during Script Analysis with the signature (Request: table) -> table, returning a response containing diagnostics.

Returns

TypeDescription
()
FieldValue
securityPluginSecurity
thread safetyUnsafe

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

NameTypeDefaultDescription
scriptLuaSourceContainerScript instance to be updated.
callbackFunctionThe function to return new script content.

Returns

TypeDescription
()
FieldValue
tags["Yields"]
securityPluginSecurity
thread safetyUnsafe

Code samples: View on Creator Hub (ScriptEditorService-UpdateSourceAsync).

Events

NameType / ReturnsDescription
ScriptEditorService.TextDocumentDidChangeFires just after a ScriptDocument changes.
ScriptEditorService.TextDocumentDidCloseFires just before a ScriptDocument object is destroyed, which happens right after the script editor closes.
ScriptEditorService.TextDocumentDidOpenFires just after a ScriptDocument object is created and parented to the service, which happens right after the script editor opens.

Inherited from Instance

NameType / ReturnsDescription
Instance.AncestryChangedFires when the Instance.Parent property of this object or one of its ancestors is changed.
Instance.AttributeChangedFires whenever an attribute is changed on the Instance.
Instance.ChildAddedFires after an object is parented to this Instance.
Instance.childAdded
Instance.ChildRemovedFires after a child is removed from this Instance.
Instance.DescendantAddedFires after a descendant is added to the Instance.
Instance.DescendantRemovingFires immediately before a descendant of the Instance is removed.
Instance.DestroyingFires immediately before (or is deferred until after) the instance is destroyed via Instance:Destroy().
Instance.StyledPropertiesChangedFires whenever any style property is changed on the instance, including when a property is set to nil.

Inherited from Object

NameType / ReturnsDescription
Object.ChangedFires 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

NameTypeDefaultDescription
documentScriptDocumentThe ScriptDocument that changed.
changesArrayVariantAn array of change structures, each describing a range that was replaced and the new text.
FieldValue
securityPluginSecurity

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

NameTypeDefaultDescription
oldDocumentScriptDocumentThe ScriptDocument that is about to be destroyed.
FieldValue
securityPluginSecurity

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

NameTypeDefaultDescription
newDocumentScriptDocumentThe newly created ScriptDocument representing the opened editor tab.
FieldValue
securityPluginSecurity

Code samples: View on Creator Hub (ScriptEditorService-TextDocumentDidOpen).

Properties

Inherited from Instance

NameType / ReturnsDescription
Instance.ArchivablebooleanDetermines if an Instance and its descendants can be cloned using Instance:Clone(), and can be saved/published.
Instance.archivableboolean
Instance.CapabilitiesSecurityCapabilitiesThe set of capabilities allowed to be used for scripts inside this container.
Instance.IsInSandboxbooleanIndicates whether the instance is inside a sandboxed container.
Instance.NamestringA non-unique identifier of the Instance.
Instance.ParentInstanceDetermines the hierarchical parent of the Instance.
Instance.PredictionModePredictionModeReflects the client-side prediction mode applied to the instance under server-authoritative physics.
Instance.RobloxLockedbooleanA deprecated property that used to protect CoreGui objects.
Instance.SandboxedbooleanWhen enabled, the instance can only access abilities in its Capabilities list.
Instance.UniqueIdUniqueIdA unique identifier for the instance.

Inherited from Object

NameType / ReturnsDescription
Object.ClassNamestringA read-only string representing the class this Object belongs to.
Object.classNamestring