Meer informatie
Engine-klasse
ScriptDocument
Niet maakbaar
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.


Samenvatting

Evenementen
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal
Overgenomen leden

API-referentie
Methoden
AddReadOnlyReasonsAsync
Opbrengst
Plugin-beveiliging
ScriptDocument:AddReadOnlyReasonsAsync(reasons:{any}):()
Parameters
reasons:{any}
Teruggaves
()
Codevoorbeelden
ScriptDocument:AddReadOnlyReasonsAsync()
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 not success then
warn(`Kon het scriptdocument niet openen: {err}`)
return
end
local scriptDocument = ScriptEditorService:FindScriptDocument(newScript)
-- Gebruik een redennaam die uniek is voor jouw plugin, zodat deze niet in conflict komt met andere plugins
scriptDocument:AddReadOnlyReasonsAsync({ "MyPluginReview" })
print(`{scriptDocument.Name} is alleen-lezen: {scriptDocument:IsReadOnly()}`)

CloseAsync
Opbrengst
Plugin-beveiliging
ScriptDocument:CloseAsync():Tuple
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

EditTextAsync
Opbrengst
Plugin-beveiliging
ScriptDocument:EditTextAsync(
newText:string, startLine:number, startCharacter:number, endLine:number, endCharacter:number
Parameters
newText:string
startLine:number
startCharacter:number
endLine:number
endCharacter:number
Teruggaves

ForceSetSelectionAsync
Opbrengst
Plugin-beveiliging
ScriptDocument:ForceSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Parameters
cursorLine:number
cursorCharacter:number
anchorLine:number?
Standaardwaarde: nil
anchorCharacter:number?
Standaardwaarde: nil
Teruggaves
Codevoorbeelden
ScriptDocument:ForceSetSelectionAsync()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
-- Verkrijg de tekst op de huidige regel van de cursor
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Dwing de hele regel tekst te selecteren
local success, err = scriptDocument:ForceSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Selectie ingesteld!")
else
print(`Selectie instellen mislukt omdat: {err}`)
end
else
print("Geen scripts open")
end

GetLine
Plugin-beveiliging
ScriptDocument:GetLine(lineIndex:number?):string
Parameters
lineIndex:number?
Standaardwaarde: nil
Teruggaves
Codevoorbeelden
ScriptDocument.SelectieVeranderd en ScriptDocument:GetRegel()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
scriptDocument.SelectieVeranderd:Connect(function(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`Geselecteerd: Regel {positionLine}, Char {positionCharacter}`)
print(`Anker: Regel {anchorLine}, Char {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Geselecteerde regel tekst: {lineText}`)
end)
else
print("Geen scripts open")
end

GetLineCount
Plugin-beveiliging
ScriptDocument:GetLineCount():number
Teruggaves
Codevoorbeelden
ScriptDocument:GetLineCount()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local lineCount = scriptDocument:GetLineCount()
print(`Het script heeft {lineCount} regels!`)
else
print("Geen scripts open")
end

GetReadOnlyReasons
Plugin-beveiliging
ScriptDocument:GetReadOnlyReasons():{string}
Teruggaves
Codevoorbeelden
ScriptDocument:GetReadOnlyReasons()
local ScriptEditorService = game:GetService("ScriptEditorService")
for _, document in ScriptEditorService:GetScriptDocuments() do
local reasons = document:GetReadOnlyReasons()
if #reasons > 0 then
print(`{document.Name} is alleen-lezen vanwege: {table.concat(reasons, ", ")}`)
end
end

GetScript
Plugin-beveiliging
ScriptDocument:GetScript():LuaSourceContainer
Codevoorbeelden
ScriptDocument:GetScript()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local openScript = scriptDocument:GetScript()
print(`Huidig geopend script: {openScript:GetFullName()}`)
else
print("Geen scripts open")
end

GetSelectedText
Plugin-beveiliging
ScriptDocument:GetSelectedText():string
Teruggaves
Codevoorbeelden
ScriptDocument:HasSelectedText() en :GetSelectedText()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
scriptDocument.SelectionChanged:Connect(function()
if scriptDocument:HasSelectedText() then
local selectedText = scriptDocument:GetSelectedText()
print(`Huidig geselecteerde tekst: {selectedText}`)
else
print("Geen tekst momenteel geselecteerd")
end
end)
else
print("Geen scripts open")
end

GetSelection
Plugin-beveiliging
ScriptDocument:GetSelection():Tuple
Teruggaves

GetSelectionEnd
Plugin-beveiliging
ScriptDocument:GetSelectionEnd():Tuple
Teruggaves
Codevoorbeelden
ScriptDocument:GetSelectionStart() en :GetSelectionEnd()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local startLine, startCharacter = scriptDocument:GetSelectionStart()
local endLine, endCharacter = scriptDocument:GetSelectionEnd()
print(`Selectie start: Regel {startLine}, Char {startCharacter}`)
print(`Selectie eind: Regel {endLine}, Char {endCharacter}`)
else
print("Geen scripts open")
end

GetSelectionStart
Plugin-beveiliging
ScriptDocument:GetSelectionStart():Tuple
Teruggaves
Codevoorbeelden
ScriptDocument:GetSelectionStart() en :GetSelectionEnd()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local startLine, startCharacter = scriptDocument:GetSelectionStart()
local endLine, endCharacter = scriptDocument:GetSelectionEnd()
print(`Selectie start: Regel {startLine}, Char {startCharacter}`)
print(`Selectie eind: Regel {endLine}, Char {endCharacter}`)
else
print("Geen scripts open")
end

GetText
Plugin-beveiliging
ScriptDocument:GetText(
startLine:number?, startCharacter:number?, endLine:number?, endCharacter:number?
Parameters
startLine:number?
Standaardwaarde: nil
startCharacter:number?
Standaardwaarde: nil
endLine:number?
Standaardwaarde: nil
endCharacter:number?
Standaardwaarde: nil
Teruggaves
Codevoorbeelden
ScriptDocument:GetText()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local text = scriptDocument:GetText()
print(`Scriptinhoud: {text}`)
else
print("Geen scripts open")
end

GetViewport
Plugin-beveiliging
ScriptDocument:GetViewport():Tuple
Teruggaves
Codevoorbeelden
ScriptDocument:GetViewport
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local firstLine, lastLine = scriptDocument:GetViewport()
print(`Momenteel bekijken lijnen {firstLine} tot {lastLine}`)
else
print("Geen scripts open")
end

HasSelectedText
Plugin-beveiliging
ScriptDocument:HasSelectedText():boolean
Teruggaves
Codevoorbeelden
ScriptDocument:HasSelectedText() en :GetSelectedText()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
scriptDocument.SelectionChanged:Connect(function()
if scriptDocument:HasSelectedText() then
local selectedText = scriptDocument:GetSelectedText()
print(`Huidig geselecteerde tekst: {selectedText}`)
else
print("Geen tekst momenteel geselecteerd")
end
end)
else
print("Geen scripts open")
end

IsCommandBar
Plugin-beveiliging
ScriptDocument:IsCommandBar():boolean
Teruggaves
Codevoorbeelden
ScriptDocument:IsCommandBar()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("Opdrachtbalkdocument:", document)
end
end

IsReadOnly
Plugin-beveiliging
ScriptDocument:IsReadOnly():boolean
Teruggaves
Codevoorbeelden
ScriptDocument:IsReadOnly()
local ScriptEditorService = game:GetService("ScriptEditorService")
for _, document in ScriptEditorService:GetScriptDocuments() do
if document:IsReadOnly() then
print(`{document.Name} is alleen-lezen`)
else
print(`{document.Name} is bewerkbaar`)
end
end

MultiEditTextAsync
Opbrengst
Plugin-beveiliging
ScriptDocument:MultiEditTextAsync(edits:{any}):Tuple
Parameters
edits:{any}
Teruggaves

RemoveReadOnlyReasonsAsync
Opbrengst
Plugin-beveiliging
ScriptDocument:RemoveReadOnlyReasonsAsync(reasons:{any}):()
Parameters
reasons:{any}
Teruggaves
()
Codevoorbeelden
ScriptDocument:RemoveReadOnlyReasonsAsync()
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 not success then
warn(`Kon het scriptdocument niet openen: {err}`)
return
end
local scriptDocument = ScriptEditorService:FindScriptDocument(newScript)
scriptDocument:AddReadOnlyReasonsAsync({ "MyPluginReview", "MyPluginLocked" })
-- De editor blijft alleen-lezen terwijl er een andere reden actief blijft
scriptDocument:RemoveReadOnlyReasonsAsync({ "MyPluginReview" })
print(`Alleen-lezen na het verwijderen van één reden: {scriptDocument:IsReadOnly()}`)
scriptDocument:RemoveReadOnlyReasonsAsync({ "MyPluginLocked" })
print(`Alleen-lezen na het verwijderen van alle redenen: {scriptDocument:IsReadOnly()}`)

RequestSetSelectionAsync
Opbrengst
Plugin-beveiliging
ScriptDocument:RequestSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Parameters
cursorLine:number
cursorCharacter:number
anchorLine:number?
Standaardwaarde: nil
anchorCharacter:number?
Standaardwaarde: nil
Teruggaves
Codevoorbeelden
ScriptDocument:RequestSetSelectionAsync()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
-- Verkrijg de tekst op de huidige regel van de cursor
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Dwing de hele regel tekst te selecteren
local success, err = scriptDocument:RequestSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Selectie ingesteld!")
else
print(`Selectie instellen mislukt omdat: {err}`)
end
else
print("Geen scripts open")
end

ReviewableTextEditsAsync
Opbrengst
Plugin-beveiliging
ScriptDocument:ReviewableTextEditsAsync(changes:{any}):Tuple
Parameters
changes:{any}
Teruggaves

Evenementen
SelectionChanged
Plugin-beveiliging
ScriptDocument.SelectionChanged(
positionLine:number, positionCharacter:number, anchorLine:number, anchorCharacter:number
Parameters
positionLine:number
positionCharacter:number
anchorLine:number
anchorCharacter:number
Codevoorbeelden
ScriptDocument.SelectieVeranderd en ScriptDocument:GetRegel()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
scriptDocument.SelectieVeranderd:Connect(function(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`Geselecteerd: Regel {positionLine}, Char {positionCharacter}`)
print(`Anker: Regel {anchorLine}, Char {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Geselecteerde regel tekst: {lineText}`)
end)
else
print("Geen scripts open")
end

ViewportChanged
Plugin-beveiliging
ScriptDocument.ViewportChanged(
startLine:number, endLine:number
Parameters
startLine:number
endLine:number
Codevoorbeelden
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)

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