Meer informatie
Engine-klasse
ScriptEditorService
Niet maakbaar
Service
Niet gerepliceerd

*Deze inhoud is vertaald met behulp van AI (bèta) en kan fouten bevatten. Klik hier om deze pagina in het Engels te bekijken.



API-referentie
Methoden
DeregisterAutocompleteCallback
Plugin-beveiliging
ScriptEditorService:DeregisterAutocompleteCallback(name:string):()
Parameters
name:string
Teruggaves
()
Codevoorbeelden
DeregisterAutocompleteCallback()
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:DeregisterAutocompleteCallback("foo")

DeregisterScriptAnalysisCallback
Plugin-beveiliging
ScriptEditorService:DeregisterScriptAnalysisCallback(name:string):()
Parameters
name:string
Teruggaves
()
Codevoorbeelden
DeregisterScriptAnalysisCallback()
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:DeregisterScriptAnalysisCallback("foo")

FindScriptDocument
Plugin-beveiliging
ScriptEditorService:FindScriptDocument(script:LuaSourceContainer):ScriptDocument
Parameters
Teruggaves
Codevoorbeelden
ScriptDocument:CloseAsync
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Vind het eerste geopende scriptdocument
for _, document in documents do
-- De Opdrachtbalk kan niet worden gesloten, dus selecteer deze niet
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Gesloten {scriptDocument.Name}`)
else
warn(`Kon {scriptDocument.Name} niet sluiten omdat: {err}`)
end
else
print("Geen geopende scripts")
end
Verbinden met ScriptDocument.ViewportChanged
--!nocheck
--[[
Om te draaien:
1. Zorg ervoor dat de Output-weergave open is
2. Voer de onderstaande code in de Command Bar uit
3. Scroll omhoog en omlaag in het geopende Script-venster
Afdrukverklaringen van het ViewportChanged-evenement verschijnen in de Output
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Maak tekst die over meerdere regels gaat
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Maak een script met de dummytekst en open het
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Kon script niet openen omdat: {err}`)
return
end
-- Verkrijg een referentie naar het geopende script
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Script Viewport Changed - startLine: {startLine}, endLine: {endLine}`)
end
-- Verbind het ViewportChanged-evenement met de bovenstaande functie die de start- en eindregel van de bijgewerkte viewport afdrukt
scriptDocument.ViewportChanged:Connect(onViewportChanged)

GetEditorSource
Plugin-beveiliging
ScriptEditorService:GetEditorSource(script:LuaSourceContainer):string
Parameters
Teruggaves

GetScriptDocuments
Plugin-beveiliging
ScriptEditorService:GetScriptDocuments():{ScriptDocument}
Teruggaves
Codevoorbeelden
Print de naam van elk script
--!nocheck
-- Voer de volgende code uit in de Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local scriptDocuments = ScriptEditorService:GetScriptDocuments()
for _, scriptDocument in scriptDocuments do
-- Print de naam van elk script
if not scriptDocument:IsCommandBar() then
print(scriptDocument.Name)
end
end

OpenScriptDocumentAsync
Opbrengst
Plugin-beveiliging
ScriptEditorService:OpenScriptDocumentAsync(
Parameters
options:Dictionary
Standaardwaarde: nil
Teruggaves
Codevoorbeelden
OpenScriptDocumentAsync()
--!nocheck
-- Voer de volgende code uit in de 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("Scriptdocument geopend")
else
print(`Kon scriptdocument niet openen: {err}`)
end
OpenScriptDocumentAsync() met InitialReadOnlyReasons
local ScriptEditorService = game:GetService("ScriptEditorService")
local Workspace = game:GetService("Workspace")
local templateScript = Instance.new("Script")
templateScript.Source = "-- Sjabloon geleverd door MyPlugin"
templateScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(templateScript, {
InitialReadOnlyReasons = { "MyPluginTemplateScript" },
})
if success then
local scriptDocument = ScriptEditorService:FindScriptDocument(templateScript)
print(`Geopend alleen-lezen sjabloon: {scriptDocument:IsReadOnly()}`)
else
warn(`Kon scriptdocument niet openen: {err}`)
end

RegisterAutocompleteCallback
Plugin-beveiliging
ScriptEditorService:RegisterAutocompleteCallback(
name:string, priority:number, callbackFunction:function
):()
Parameters
name:string
priority:number
callbackFunction:function
Teruggaves
()
Codevoorbeelden
RegisterAutocompleteCallback() en DeregisterAutocompleteCallback()
--!nocheck
-- Voer de volgende code uit in de 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)
-- Om de callback te deregistreren, voer de volgende code uit in de Command Bar
ScriptEditorService:DeregisterAutocompleteCallback("foo")

RegisterScriptAnalysisCallback
Plugin-beveiliging
ScriptEditorService:RegisterScriptAnalysisCallback(
name:string, priority:number, callbackFunction:function
):()
Parameters
name:string
priority:number
callbackFunction:function
Teruggaves
()
Codevoorbeelden
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
-- Itereer regel voor regel
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 hier gevonden!",
severity = Enum.Severity.Warning,
})
end
lineNo = lineNo + #newline:gsub("\n+", "\\0%0\\0"):gsub(".%z.", "."):gsub("%z", "")
end
return response
end)

UpdateSourceAsync
Opbrengst
Plugin-beveiliging
ScriptEditorService:UpdateSourceAsync(
script:LuaSourceContainer, callback:function
):()
Parameters
callback:function
Teruggaves
()
Codevoorbeelden
Update Source Async
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:UpdateSourceAsync(workspace.Script, function(oldContent)
return oldContent .. " Wereld!"
end)

Evenementen
TextDocumentDidChange
Plugin-beveiliging
ScriptEditorService.TextDocumentDidChange(
document:ScriptDocument, changesArray:Variant
Parameters
changesArray:Variant
Codevoorbeelden
ScriptEditorService.TextDocumentDidChange
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidChange:Connect(function(scriptDocument, changes)
print("Gewijzigd", scriptDocument, changes)
end)

TextDocumentDidClose
Plugin-beveiliging
ScriptEditorService.TextDocumentDidClose(oldDocument:ScriptDocument):RBXScriptSignal
Parameters
oldDocument:ScriptDocument
Codevoorbeelden
ScriptEditorService.TextDocumentDidClose
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidClose:Connect(function(scriptDocument)
print("Gesloten", scriptDocument)
end)

TextDocumentDidOpen
Plugin-beveiliging
ScriptEditorService.TextDocumentDidOpen(newDocument:ScriptDocument):RBXScriptSignal
Parameters
newDocument:ScriptDocument
Codevoorbeelden
ScriptEditorService.TextDocumentDidOpen
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidOpen:Connect(function(scriptDocument)
print("Geopend", scriptDocument)
end)

©2026 Roblox Corporation. Roblox, het Roblox-logo en Powering Imagination behoren tot onze geregistreerde en niet-geregistreerde handelsmerken in de VS en andere landen.