Pelajari
Kelas Engine
ScriptDocument
Tidak Dapat Dibuat
Tidak Direplikasi

*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.


Rangkuman
Metode
EditTextAsync(newText: string,startLine: number,startCharacter: number,endLine: number,endCharacter: number):Tuple
ForceSetSelectionAsync(cursorLine: number,cursorCharacter: number,anchorLine: number?,anchorCharacter: number?):Tuple
GetLine(lineIndex: number?):string
GetText(startLine: number?,startCharacter: number?,endLine: number?,endCharacter: number?):string
RequestSetSelectionAsync(cursorLine: number,cursorCharacter: number,anchorLine: number?,anchorCharacter: number?):Tuple
Acara
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal
Anggota yang Diwariskan

Referensi API
Metode
CloseAsync
Hasil
Keamanan Plugin
ScriptDocument:CloseAsync():Tuple
Memberikan nilai
Contoh Kode
ScriptDocument:TutupAsync
--!nocheck
-- Jalankan kode berikut di Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Temukan dokumen skrip yang terbuka pertama
for _, document in documents do
-- Command Bar tidak bisa ditutup, jadi jangan pilih itu
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Tutup {scriptDocument.Name}`)
else
warn(`Gagal untuk menutup {scriptDocument.Name} karena: {err}`)
end
else
print("Tidak ada skrip yang terbuka")
end

EditTextAsync
Hasil
Keamanan Plugin
ScriptDocument:EditTextAsync(
newText:string, startLine:number, startCharacter:number, endLine:number, endCharacter:number
Parameter
newText:string
startLine:number
startCharacter:number
endLine:number
endCharacter:number
Memberikan nilai

ForceSetSelectionAsync
Hasil
Keamanan Plugin
ScriptDocument:ForceSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Parameter
cursorLine:number
cursorCharacter:number
anchorLine:number?
Nilai Default: "nil"
anchorCharacter:number?
Nilai Default: "nil"
Memberikan nilai
Contoh Kode
ScriptDocument:ForceSetSelectionAsync()
--!nocheck
-- Jalankan kode berikut di Command Bar saat sebuah skrip terbuka
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
-- Dapatkan teks pada baris saat ini di kursor
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Paksa pilih seluruh baris teks
local success, err = scriptDocument:ForceSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Pemilihan telah diatur!")
else
print(`Gagal mengatur pemilihan karena: {err}`)
end
else
print("Tidak ada skrip yang terbuka")
end

GetLine
Keamanan Plugin
ScriptDocument:GetLine(lineIndex:number?):string
Parameter
lineIndex:number?
Nilai Default: "nil"
Memberikan nilai
Contoh Kode
ScriptDocument.SelectionChanged dan ScriptDocument:GetLine()
--!nocheck
-- Jalankan kode berikut di Command Bar saat skrip terbuka
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(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`Terpilih: Baris {positionLine}, Karakter {positionCharacter}`)
print(`Jangkar: Baris {anchorLine}, Karakter {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Teks baris yang dipilih: {lineText}`)
end)
else
print("Tidak ada skrip yang terbuka")
end

GetLineCount
Keamanan Plugin
ScriptDocument:GetLineCount():number
Memberikan nilai
Contoh Kode
SkripDokumen:GetJumlahBaris()
--!nocheck
-- Jalankan kode berikut di Command Bar saat skrip terbuka
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(`Skrip memiliki {lineCount} baris!`)
else
print("Tidak ada skrip yang terbuka")
end

GetScript
Keamanan Plugin
ScriptDocument:GetScript():LuaSourceContainer
Memberikan nilai
Contoh Kode
ScriptDocument:AmbilScript()
--!nocheck
-- Jalankan kode berikut di Command Bar saat sebuah skrip terbuka
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(`Skrip yang terbuka saat ini: {openScript:GetFullName()}`)
else
print("Tidak ada skrip yang terbuka")
end

GetSelectedText
Keamanan Plugin
ScriptDocument:GetSelectedText():string
Memberikan nilai
Contoh Kode
ScriptDocument:MemilikiTeksYangDipilih() dan :DapatkanTeksYangDipilih()
--!nocheck
-- Jalankan kode berikut di Command Bar saat skrip terbuka
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(`Teks yang saat ini dipilih: {selectedText}`)
else
print("Tidak ada teks yang saat ini dipilih")
end
end)
else
print("Tidak ada skrip yang terbuka")
end

GetSelection
Keamanan Plugin
ScriptDocument:GetSelection():Tuple
Memberikan nilai

GetSelectionEnd
Keamanan Plugin
ScriptDocument:GetSelectionEnd():Tuple
Memberikan nilai
Contoh Kode
ScriptDocument:GetSelectionStart() dan :GetSelectionEnd()
--!nocheck
-- Jalankan kode berikut di Command Bar saat sebuah skrip terbuka
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(`Selection start: Line {startLine}, Karakter {startCharacter}`)
print(`Selection end: Line {endLine}, Karakter {endCharacter}`)
else
print("Tidak ada skrip yang terbuka")
end

GetSelectionStart
Keamanan Plugin
ScriptDocument:GetSelectionStart():Tuple
Memberikan nilai
Contoh Kode
ScriptDocument:GetSelectionStart() dan :GetSelectionEnd()
--!nocheck
-- Jalankan kode berikut di Command Bar saat sebuah skrip terbuka
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(`Selection start: Line {startLine}, Karakter {startCharacter}`)
print(`Selection end: Line {endLine}, Karakter {endCharacter}`)
else
print("Tidak ada skrip yang terbuka")
end

GetText
Keamanan Plugin
ScriptDocument:GetText(
startLine:number?, startCharacter:number?, endLine:number?, endCharacter:number?
Parameter
startLine:number?
Nilai Default: "nil"
startCharacter:number?
Nilai Default: "nil"
endLine:number?
Nilai Default: "nil"
endCharacter:number?
Nilai Default: "nil"
Memberikan nilai
Contoh Kode
ScriptDocument:GetText()
--!nocheck
-- Jalankan kode berikut di Command Bar saat sebuah skrip terbuka
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(`Isi skrip: {text}`)
else
print("Tidak ada skrip yang terbuka")
end

GetViewport
Keamanan Plugin
ScriptDocument:GetViewport():Tuple
Memberikan nilai
Contoh Kode
ScriptDocument:GetViewport
--!nocheck
-- Jalankan kode berikut di Command Bar saat skrip terbuka
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(`Saat ini melihat baris {firstLine} hingga {lastLine}`)
else
print("Tidak ada skrip yang terbuka")
end

HasSelectedText
Keamanan Plugin
ScriptDocument:HasSelectedText():boolean
Memberikan nilai
Contoh Kode
ScriptDocument:MemilikiTeksYangDipilih() dan :DapatkanTeksYangDipilih()
--!nocheck
-- Jalankan kode berikut di Command Bar saat skrip terbuka
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(`Teks yang saat ini dipilih: {selectedText}`)
else
print("Tidak ada teks yang saat ini dipilih")
end
end)
else
print("Tidak ada skrip yang terbuka")
end

IsCommandBar
Keamanan Plugin
ScriptDocument:IsCommandBar():boolean
Memberikan nilai
Contoh Kode
ScriptDocument:IsCommandBar()
--!nocheck
-- Jalankan kode berikut di Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("Dokumen command bar:", document)
end
end

MultiEditTextAsync
Hasil
Keamanan Plugin
ScriptDocument:MultiEditTextAsync(edits:{any}):Tuple
Parameter
edits:{any}
Memberikan nilai

RequestSetSelectionAsync
Hasil
Keamanan Plugin
ScriptDocument:RequestSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Parameter
cursorLine:number
cursorCharacter:number
anchorLine:number?
Nilai Default: "nil"
anchorCharacter:number?
Nilai Default: "nil"
Memberikan nilai
Contoh Kode
ScriptDocument:RequestSetSelectionAsync()
--!nocheck
-- Jalankan kode berikut di Command Bar saat sebuah skrip terbuka
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
-- Ambil teks di baris saat ini di kursor
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Paksa pilih seluruh baris teks
local success, err = scriptDocument:RequestSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Pemilihan berhasil!")
else
print(`Gagal untuk menetapkan pemilihan karena: {err}`)
end
else
print("Tidak ada skrip terbuka")
end

Acara
SelectionChanged
Keamanan Plugin
ScriptDocument.SelectionChanged(
positionLine:number, positionCharacter:number, anchorLine:number, anchorCharacter:number
Parameter
positionLine:number
positionCharacter:number
anchorLine:number
anchorCharacter:number
Contoh Kode
ScriptDocument.SelectionChanged dan ScriptDocument:GetLine()
--!nocheck
-- Jalankan kode berikut di Command Bar saat skrip terbuka
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(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`Terpilih: Baris {positionLine}, Karakter {positionCharacter}`)
print(`Jangkar: Baris {anchorLine}, Karakter {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Teks baris yang dipilih: {lineText}`)
end)
else
print("Tidak ada skrip yang terbuka")
end

ViewportChanged
Keamanan Plugin
ScriptDocument.ViewportChanged(
startLine:number, endLine:number
Parameter
startLine:number
endLine:number
Contoh Kode
Menghubungkan ke ScriptDocument.ViewportChanged
--!nocheck
--[[
Untuk menjalankan:
1. Pastikan tampilan Output terbuka
2. Jalankan kode di bawah ini di Command Bar
3. Gulir ke atas dan ke bawah di jendela Skrip yang terbuka
Pernyataan print dari peristiwa ViewportChanged akan muncul di Output
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Buat teks yang membentang banyak baris
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Buat skrip yang berisi teks dummy dan buka
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Gagal membuka skrip karena: {err}`)
return
end
-- Dapatkan referensi ke skrip yang dibuka
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Viewport Skrip Berubah - startLine: {startLine}, endLine: {endLine}`)
end
-- Hubungkan peristiwa ViewportChanged ke fungsi di atas yang mencetak garis awal dan akhir dari viewport yang diperbarui
scriptDocument.ViewportChanged:Connect(onViewportChanged)

©2026 Roblox Corporation. Roblox, logo Roblox, dan Powering Imagination termasuk dalam merek dagang kami yang terdaftar dan tidak terdaftar di AS dan negara lainnya.