Learn
Engine Class
ScriptEditorService
Not Creatable
Service
Not Replicated


API Reference
Methods
DeregisterAutocompleteCallback
Plugin Security
ScriptEditorService:DeregisterAutocompleteCallback(name:string):()
Parameters
name:string
Returns
()
Code Samples
DeregisterAutocompleteCallback()
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:DeregisterAutocompleteCallback("foo")

DeregisterScriptAnalysisCallback
Plugin Security
ScriptEditorService:DeregisterScriptAnalysisCallback(name:string):()
Parameters
name:string
Returns
()
Code Samples
DeregisterScriptAnalysisCallback()
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:DeregisterScriptAnalysisCallback("foo")

FindScriptDocument
Plugin Security
ScriptEditorService:FindScriptDocument(script:LuaSourceContainer):ScriptDocument
Parameters
Code Samples
ScriptDocument:CloseAsync
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Find the first open script document
for _, document in documents do
-- The Command Bar can't be closed, so don't select it
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Closed {scriptDocument.Name}`)
else
warn(`Failed to close {scriptDocument.Name} because: {err}`)
end
else
print("No open scripts")
end
Connecting to ScriptDocument.ViewportChanged
--!nocheck
--[[
To run:
1. Ensure Output view is open
2. Run the below code in the Command Bar
3. Scroll up and down in the opened Script window
Print statements from the ViewportChanged event will appear in the Output
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Create text that spans many lines
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Create a script containing the dummy text and open it
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Failed to open script because: {err}`)
return
end
-- Get a reference to the opened script
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Script Viewport Changed - startLine: {startLine}, endLine: {endLine}`)
end
-- Connect the ViewportChanged event to the function above that prints the start and end line of the updated viewport
scriptDocument.ViewportChanged:Connect(onViewportChanged)

GetEditorSource
Plugin Security
ScriptEditorService:GetEditorSource(script:LuaSourceContainer):string
Parameters
Returns

GetScriptDocuments
Plugin Security
ScriptEditorService:GetScriptDocuments():{ScriptDocument}
Code Samples
Print the name of every script
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local scriptDocuments = ScriptEditorService:GetScriptDocuments()
for _, scriptDocument in scriptDocuments do
-- Prints the name of each script
if not scriptDocument:IsCommandBar() then
print(scriptDocument.Name)
end
end

OpenScriptDocumentAsync
Yields
Plugin Security
ScriptEditorService:OpenScriptDocumentAsync(
Parameters
options:Dictionary
Default Value: "nil"
Returns
Code Samples
OpenScriptDocumentAsync()
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local Workspace = game:GetService("Workspace")
local newScript = Instance.new("Script")
newScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(newScript)
if success then
print("Opened script document")
else
print(`Failed to open script document: {err}`)
end

RegisterAutocompleteCallback
Plugin Security
ScriptEditorService:RegisterAutocompleteCallback(
name:string, priority:number, callbackFunction:function
):()
Parameters
name:string
priority:number
callbackFunction:function
Returns
()
Code Samples
RegisterAutocompleteCallback() and DeregisterAutocompleteCallback()
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
type Request = {
position: {
line: number,
character: number,
},
textDocument: {
document: ScriptDocument?,
script: LuaSourceContainer?,
},
}
type Response = {
items: {
{
label: string,
kind: Enum.CompletionItemKind?,
tags: { Enum.CompletionItemTag }?,
detail: string?,
documentation: {
value: string,
}?,
overloads: number?,
learnMoreLink: string?,
codeSample: string?,
preselect: boolean?,
textEdit: {
newText: string,
replace: {
start: { line: number, character: number },
["end"]: { line: number, character: number },
},
}?,
}
},
}
local autocompleteCallback = function(request: Request, response: Response): Response
local item = {
label = "foo",
preselect = true,
}
table.insert(response.items, item)
return response
end
ScriptEditorService:RegisterAutocompleteCallback("foo", 1, autocompleteCallback)
-- To deregister the callback, run the following code in the Command Bar
ScriptEditorService:DeregisterAutocompleteCallback("foo")

RegisterScriptAnalysisCallback
Plugin Security
ScriptEditorService:RegisterScriptAnalysisCallback(
name:string, priority:number, callbackFunction:function
):()
Parameters
name:string
priority:number
callbackFunction:function
Returns
()
Code Samples
RegisterScriptAnalysisCallback()
type Request = {
["script"]: LuaSourceContainer,
}
type Response = {
diagnostics: {
{
range: {
start: {
line: number,
character: number,
},
["end"]: {
line: number,
character: number,
},
},
code: string?,
message: string,
severity: Enum.Severity?,
codeDescription: { href: string }?,
}
},
}
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:RegisterScriptAnalysisCallback("foo", 1, function(Req: Request): Response
local response = {
diagnostics = {},
}
local lineNo = 1
-- Iterate line by line
for text, newline in Req.script.Source:gmatch("([^\r\n]*)([\r\n]*)") do
local startIndex, endIndex = string.find(text, "Foo")
if startIndex and endIndex then
table.insert(response.diagnostics, {
range = {
["start"] = {
line = lineNo,
character = startIndex,
},
["end"] = {
line = lineNo,
character = endIndex,
},
},
code = "FooFinder",
message = "Foo found here!",
severity = Enum.Severity.Warning,
})
end
lineNo = lineNo + #newline:gsub("\n+", "\0%0\0"):gsub(".%z.", "."):gsub("%z", "")
end
return response
end)

UpdateSourceAsync
Yields
Plugin Security
ScriptEditorService:UpdateSourceAsync(
script:LuaSourceContainer, callback:function
):()
Parameters
callback:function
Returns
()

Events
TextDocumentDidChange
Plugin Security
ScriptEditorService.TextDocumentDidChange(
document:ScriptDocument, changesArray:Variant
Parameters
changesArray:Variant
Code Samples
ScriptEditorService.TextDocumentDidChange
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidChange:Connect(function(scriptDocument, changes)
print("Changed", scriptDocument, changes)
end)

TextDocumentDidClose
Plugin Security
ScriptEditorService.TextDocumentDidClose(oldDocument:ScriptDocument):RBXScriptSignal
Parameters
oldDocument:ScriptDocument
Code Samples
ScriptEditorService.TextDocumentDidClose
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidClose:Connect(function(scriptDocument)
print("Closed", scriptDocument)
end)

TextDocumentDidOpen
Plugin Security
ScriptEditorService.TextDocumentDidOpen(newDocument:ScriptDocument):RBXScriptSignal
Parameters
newDocument:ScriptDocument
Code Samples
ScriptEditorService.TextDocumentDidOpen
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidOpen:Connect(function(scriptDocument)
print("Opened", scriptDocument)
end)

©2026 Roblox Corporation. Roblox, the Roblox logo and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.