Ghi chú phát hành
Học
Lớp công cụ
ScriptDocument
Không Thể Tạo
Không Sao Chép

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.


Tóm Tắt
Phương Pháp
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
Sự Kiện
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal
Thành viên kế thừa

Tài Liệu Tham Khảo API
Phương Pháp
CloseAsync
Sinh Lợi
Bảo Mật Plugin
ScriptDocument:CloseAsync():Tuple
Lợi Nhuận
Mẫu mã
ScriptDocument:CloseAsync
--!nocheck
-- Chạy mã sau trong Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Tìm tài liệu script mở đầu tiên
for _, document in documents do
-- Command Bar không thể bị đóng, vì vậy không chọn nó
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Đã đóng {scriptDocument.Name}`)
else
warn(`Không thể đóng {scriptDocument.Name} vì: {err}`)
end
else
print("Không có script nào đang mở")
end

EditTextAsync
Sinh Lợi
Bảo Mật Plugin
ScriptDocument:EditTextAsync(
newText:string, startLine:number, startCharacter:number, endLine:number, endCharacter:number
Tham Số
newText:string
startLine:number
startCharacter:number
endLine:number
endCharacter:number
Lợi Nhuận

ForceSetSelectionAsync
Sinh Lợi
Bảo Mật Plugin
ScriptDocument:ForceSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Tham Số
cursorLine:number
cursorCharacter:number
anchorLine:number?
Giá Trị Mặc Định: "nil"
anchorCharacter:number?
Giá Trị Mặc Định: "nil"
Lợi Nhuận
Mẫu mã
Tài liệu Script:ForceSetSelectionAsync()
--!nocheck
-- Chạy đoạn mã sau trong Command Bar trong khi một script đang mở
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
-- Lấy văn bản trên dòng hiện tại của con trỏ
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Buộc chọn toàn bộ dòng văn bản
local success, err = scriptDocument:ForceSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Đã thiết lập lựa chọn!")
else
print(`Không thể thiết lập lựa chọn vì: {err}`)
end
else
print("Không có script nào đang mở")
end

GetLine
Bảo Mật Plugin
ScriptDocument:GetLine(lineIndex:number?):string
Tham Số
lineIndex:number?
Giá Trị Mặc Định: "nil"
Lợi Nhuận
Mẫu mã
ScriptDocument.SelectionChanged và ScriptDocument:GetLine()
--!nocheck
-- Chạy mã sau trong Command Bar khi một script đang mở
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(`Đã chọn: Dòng {positionLine}, Ký tự {positionCharacter}`)
print(`Chốt: Dòng {anchorLine}, Ký tự {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Nội dung dòng đã chọn: {lineText}`)
end)
else
print("Không có script nào mở")
end

GetLineCount
Bảo Mật Plugin
ScriptDocument:GetLineCount():number
Lợi Nhuận
Mẫu mã
ScriptDocument:GetLineCount()
--!nocheck
-- Chạy đoạn mã sau trong Command Bar khi một script đang mở
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(`Script có {lineCount} dòng!`)
else
print("Không có script nào đang mở")
end

GetScript
Bảo Mật Plugin
ScriptDocument:GetScript():LuaSourceContainer
Lợi Nhuận
Mẫu mã
ScriptDocument:GetScript()
--!nocheck
-- Chạy mã sau trong Command Bar khi một script đang mở
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(`Script hiện đang mở: {openScript:GetFullName()}`)
else
print("Không có script nào đang mở")
end

GetSelectedText
Bảo Mật Plugin
ScriptDocument:GetSelectedText():string
Lợi Nhuận
Mẫu mã
ScriptDocument:HasSelectedText() và :GetSelectedText()
--!nocheck
-- Chạy mã sau trong Command Bar khi một tập lệnh đang mở
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(`Văn bản hiện đang được chọn: {selectedText}`)
else
print("Không có văn bản nào được chọn")
end
end)
else
print("Không có tập lệnh nào đang mở")
end

GetSelection
Bảo Mật Plugin
ScriptDocument:GetSelection():Tuple
Lợi Nhuận

GetSelectionEnd
Bảo Mật Plugin
ScriptDocument:GetSelectionEnd():Tuple
Lợi Nhuận
Mẫu mã
ScriptDocument:GetSelectionStart() và :GetSelectionEnd()
--!nocheck
-- Chạy mã sau trong Command Bar khi một script đang mở
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(`Điểm bắt đầu lựa chọn: Dòng {startLine}, Ký tự {startCharacter}`)
print(`Điểm kết thúc lựa chọn: Dòng {endLine}, Ký tự {endCharacter}`)
else
print("Không có script nào đang mở")
end

GetSelectionStart
Bảo Mật Plugin
ScriptDocument:GetSelectionStart():Tuple
Lợi Nhuận
Mẫu mã
ScriptDocument:GetSelectionStart() và :GetSelectionEnd()
--!nocheck
-- Chạy mã sau trong Command Bar khi một script đang mở
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(`Điểm bắt đầu lựa chọn: Dòng {startLine}, Ký tự {startCharacter}`)
print(`Điểm kết thúc lựa chọn: Dòng {endLine}, Ký tự {endCharacter}`)
else
print("Không có script nào đang mở")
end

GetText
Bảo Mật Plugin
ScriptDocument:GetText(
startLine:number?, startCharacter:number?, endLine:number?, endCharacter:number?
Tham Số
startLine:number?
Giá Trị Mặc Định: "nil"
startCharacter:number?
Giá Trị Mặc Định: "nil"
endLine:number?
Giá Trị Mặc Định: "nil"
endCharacter:number?
Giá Trị Mặc Định: "nil"
Lợi Nhuận
Mẫu mã
ScriptDocument:GetText()
--!nocheck
-- Run the following code in the Command Bar while a script is open
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(`Script contents: {text}`)
else
print("No scripts open")
end

GetViewport
Bảo Mật Plugin
ScriptDocument:GetViewport():Tuple
Lợi Nhuận
Mẫu mã
ScriptDocument:GetViewport
---!nocheck
-- Chạy mã sau trong Command Bar khi một kịch bản đang mở
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(`Hiện tại đang xem các dòng {firstLine} đến {lastLine}`)
else
print("Không có kịch bản nào được mở")
end

HasSelectedText
Bảo Mật Plugin
ScriptDocument:HasSelectedText():boolean
Lợi Nhuận
Mẫu mã
ScriptDocument:HasSelectedText() và :GetSelectedText()
--!nocheck
-- Chạy mã sau trong Command Bar khi một tập lệnh đang mở
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(`Văn bản hiện đang được chọn: {selectedText}`)
else
print("Không có văn bản nào được chọn")
end
end)
else
print("Không có tập lệnh nào đang mở")
end

IsCommandBar
Bảo Mật Plugin
ScriptDocument:IsCommandBar():boolean
Lợi Nhuận
Mẫu mã
ScriptDocument:IsCommandBar()
--!nocheck
-- Chạy đoạn mã sau trong Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("Tài liệu command bar:", document)
end
end

MultiEditTextAsync
Sinh Lợi
Bảo Mật Plugin
ScriptDocument:MultiEditTextAsync(edits:{any}):Tuple
Tham Số
edits:{any}
Lợi Nhuận

RequestSetSelectionAsync
Sinh Lợi
Bảo Mật Plugin
ScriptDocument:RequestSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Tham Số
cursorLine:number
cursorCharacter:number
anchorLine:number?
Giá Trị Mặc Định: "nil"
anchorCharacter:number?
Giá Trị Mặc Định: "nil"
Lợi Nhuận
Mẫu mã
Tài liệu kịch bản: Yêu cầu đặt lựa chọn bất đồng bộ()
--!nocheck
-- Chạy đoạn mã sau trong Thanh Lệnh khi một kịch bản đang mở
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
-- Lấy văn bản trên dòng hiện tại của con trỏ
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Buộc chọn toàn bộ dòng văn bản
local success, err = scriptDocument:RequestSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Đã đặt lựa chọn!")
else
print(`Không thể đặt lựa chọn vì: {err}`)
end
else
print("Không có kịch bản nào mở")
end

Sự Kiện
SelectionChanged
Bảo Mật Plugin
ScriptDocument.SelectionChanged(
positionLine:number, positionCharacter:number, anchorLine:number, anchorCharacter:number
Tham Số
positionLine:number
positionCharacter:number
anchorLine:number
anchorCharacter:number
Mẫu mã
ScriptDocument.SelectionChanged và ScriptDocument:GetLine()
--!nocheck
-- Chạy mã sau trong Command Bar khi một script đang mở
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(`Đã chọn: Dòng {positionLine}, Ký tự {positionCharacter}`)
print(`Chốt: Dòng {anchorLine}, Ký tự {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Nội dung dòng đã chọn: {lineText}`)
end)
else
print("Không có script nào mở")
end

ViewportChanged
Bảo Mật Plugin
ScriptDocument.ViewportChanged(
startLine:number, endLine:number
Tham Số
startLine:number
endLine:number
Mẫu mã
Kết nối với ScriptDocument.ViewportChanged
--!nocheck
--[[
Để chạy:
1. Đảm bảo rằng khung Output đang mở
2. Chạy đoạn mã bên dưới trong Command Bar
3. Cuộn lên và xuống trong cửa sổ Script đã mở
Các câu lệnh Print từ sự kiện ViewportChanged sẽ xuất hiện trong Output
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Tạo văn bản trải dài nhiều dòng
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Tạo một script chứa văn bản dummy và mở nó
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Không thể mở script vì: {err}`)
return
end
-- Lấy tham chiếu đến script đã mở
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Viewport Script Đã Thay Đổi - startLine: {startLine}, endLine: {endLine}`)
end
-- Kết nối sự kiện ViewportChanged với hàm ở trên để in ra dòng bắt đầu và kết thúc của viewport được cập nhật
scriptDocument.ViewportChanged:Connect(onViewportChanged)

©2026 Roblox Corporation. Roblox, logo Roblox và Powering Imagination là các nhãn hiệu đã đăng ký và chưa đăng ký của chúng tôi tại Hoa Kỳ và các quốc gia khác.