Ghi chú phát hành
Học
Lớp công cụ
ScriptEditorService
Không Thể Tạo
Dịch Vụ
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ài Liệu Tham Khảo API
Phương Pháp
DeregisterAutocompleteCallback
Bảo Mật Plugin
ScriptEditorService:DeregisterAutocompleteCallback(name:string):()
Tham Số
name:string
Lợi Nhuận
()
Mẫu mã
Hủy Đăng Ký Callback Tự Động Hoàn Thành()
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Hủy đăng ký callback tự động hoàn thành cho "foo"
ScriptEditorService:DeregisterAutocompleteCallback("foo")

DeregisterScriptAnalysisCallback
Bảo Mật Plugin
ScriptEditorService:DeregisterScriptAnalysisCallback(name:string):()
Tham Số
name:string
Lợi Nhuận
()
Mẫu mã
Hủy đăng ký Phân tích kịch bản Callback()
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:DeregisterScriptAnalysisCallback("foo")

FindScriptDocument
Bảo Mật Plugin
ScriptEditorService:FindScriptDocument(script:LuaSourceContainer):ScriptDocument
Tham Số
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
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)

GetEditorSource
Bảo Mật Plugin
ScriptEditorService:GetEditorSource(script:LuaSourceContainer):string
Tham Số
Lợi Nhuận

GetScriptDocuments
Bảo Mật Plugin
ScriptEditorService:GetScriptDocuments():{ScriptDocument}
Lợi Nhuận
Mẫu mã
In danh sách tên của mọi script
--!nocheck
-- Chạy mã sau trong Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local scriptDocuments = ScriptEditorService:GetScriptDocuments()
for _, scriptDocument in scriptDocuments do
-- In tên của mỗi script
if not scriptDocument:IsCommandBar() then
print(scriptDocument.Name)
end
end

OpenScriptDocumentAsync
Sinh Lợi
Bảo Mật Plugin
ScriptEditorService:OpenScriptDocumentAsync(
Tham Số
options:Dictionary
Giá Trị Mặc Định: "nil"
Lợi Nhuận
Mẫu mã
MởTàiLiệuKịchBảnAsync()
--!nocheck
-- Chạy đoạn mã sau trong Thanh Lệnh
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("Đã mở tài liệu kịch bản")
else
print(`Không thể mở tài liệu kịch bản: {err}`)
end

RegisterAutocompleteCallback
Bảo Mật Plugin
ScriptEditorService:RegisterAutocompleteCallback(
name:string, priority:number, callbackFunction:function
):()
Tham Số
name:string
priority:number
callbackFunction:function
Lợi Nhuận
()
Mẫu mã
Đăng kýCallbackTựĐộngHoànTất() và HuỷĐăngKýCallbackTựĐộngHoànTất()
--!nocheck
-- Chạy đoạn mã sau trong 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)
-- Để huỷ đăng ký callback, hãy chạy đoạn mã sau trong Command Bar
ScriptEditorService:DeregisterAutocompleteCallback("foo")

RegisterScriptAnalysisCallback
Bảo Mật Plugin
ScriptEditorService:RegisterScriptAnalysisCallback(
name:string, priority:number, callbackFunction:function
):()
Tham Số
name:string
priority:number
callbackFunction:function
Lợi Nhuận
()
Mẫu mã
ĐăngKýPhânTíchScriptCallback()
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
-- Lặp qua từng dòng
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 được tìm thấy ở đây!",
severity = Enum.Severity.Warning,
})
end
lineNo = lineNo + #newline:gsub("\n+", "\\0%0\\0"):gsub(".%z.", "."):gsub("%z", "")
end
return response
end)

UpdateSourceAsync
Sinh Lợi
Bảo Mật Plugin
ScriptEditorService:UpdateSourceAsync(
script:LuaSourceContainer, callback:function
):()
Tham Số
callback:function
Lợi Nhuận
()

Sự Kiện
TextDocumentDidChange
Bảo Mật Plugin
ScriptEditorService.TextDocumentDidChange(
document:ScriptDocument, changesArray:Variant
Tham Số
changesArray:Variant
Mẫu mã
ScriptEditorService.TextDocumentDidChange
--!nocheck
-- Chạy đoạn mã sau trong thanh lệnh
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidChange:Connect(function(scriptDocument, changes)
print("Đã thay đổi", scriptDocument, changes)
end)

TextDocumentDidClose
Bảo Mật Plugin
ScriptEditorService.TextDocumentDidClose(oldDocument:ScriptDocument):RBXScriptSignal
Tham Số
oldDocument:ScriptDocument
Mẫu mã
Dịch vụChỉnh sửaKịch bản.Tài liệuKịch bảnĐãĐóng
--!nocheck
-- Chạy mã sau trong Thanh Lệnh
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidClose:Connect(function(scriptDocument)
print("Đã Đóng", scriptDocument)
end)

TextDocumentDidOpen
Bảo Mật Plugin
ScriptEditorService.TextDocumentDidOpen(newDocument:ScriptDocument):RBXScriptSignal
Tham Số
newDocument:ScriptDocument
Mẫu mã
Dịch vụ Chỉnh sửa Kịch bản.Tài liệu Kịch bản Đã Mở
`--!nocheck`
`-- Chạy đoạn mã sau trong Command Bar`
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidOpen:Connect(function(scriptDocument)
print("Đã mở", scriptDocument)
end)

©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.