学ぶ
エンジンクラス
ScriptDocument
作成できません
複製されていません

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。


概要
方法
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
イベント
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal
継承されたメンバー

APIリファレンス
方法
CloseAsync
イールド
プラグインのセキュリティ
ScriptDocument:CloseAsync():Tuple
戻り値
コードサンプル
ScriptDocument:CloseAsync
--!nocheck
-- 次のコードをコマンドバーで実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- 最初に開いているスクリプトドキュメントを見つける
for _, document in documents do
-- コマンドバーは閉じることができないので、選択しないでください
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`閉じました {scriptDocument.Name}`)
else
warn(`{scriptDocument.Name} を閉じるのに失敗しました: {err}`)
end
else
print("開いているスクリプトはありません")
end

EditTextAsync
イールド
プラグインのセキュリティ
ScriptDocument:EditTextAsync(
newText:string, startLine:number, startCharacter:number, endLine:number, endCharacter:number
パラメータ
newText:string
startLine:number
startCharacter:number
endLine:number
endCharacter:number
戻り値

ForceSetSelectionAsync
イールド
プラグインのセキュリティ
ScriptDocument:ForceSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
パラメータ
cursorLine:number
cursorCharacter:number
anchorLine:number?
既定値: "nil"
anchorCharacter:number?
既定値: "nil"
戻り値
コードサンプル
スクリプト文書: ForceSetSelectionAsync()
--!nocheck
-- スクリプトが開いている間にコマンドバーで次のコードを実行します
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 cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- テキストの全行を強制的に選択します
local success, err = scriptDocument:ForceSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("選択が設定されました!")
else
print(`選択の設定に失敗しました: {err}`)
end
else
print("スクリプトが開いていません")
end

GetLine
プラグインのセキュリティ
ScriptDocument:GetLine(lineIndex:number?):string
パラメータ
lineIndex:number?
既定値: "nil"
戻り値
コードサンプル
ScriptDocument.SelectionChanged と ScriptDocument:GetLine()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
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(`選択された: 行 {positionLine}, 文字 {positionCharacter}`)
print(`アンカー: 行 {anchorLine}, 文字 {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`選択された行のテキスト: {lineText}`)
end)
else
print("スクリプトが開いていません")
end

GetLineCount
プラグインのセキュリティ
ScriptDocument:GetLineCount():number
戻り値
コードサンプル
スクリプトドキュメント:GetLineCount()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
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(`スクリプトは {lineCount} 行あります!`)
else
print("開いているスクリプトはありません")
end

GetScript
プラグインのセキュリティ
ScriptDocument:GetScript():LuaSourceContainer
コードサンプル
ScriptDocument:GetScript()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
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(`現在開いているスクリプト: {openScript:GetFullName()}`)
else
print("スクリプトが開いていません")
end

GetSelectedText
プラグインのセキュリティ
ScriptDocument:GetSelectedText():string
戻り値
コードサンプル
ScriptDocument:HasSelectedText() と :GetSelectedText()
--!nocheck
-- スクリプトが開いている間に、コマンドバーで以下のコードを実行してください
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(`現在選択されているテキスト: {selectedText}`)
else
print("現在選択されているテキストはありません")
end
end)
else
print("スクリプトは開いていません")
end

GetSelection
プラグインのセキュリティ
ScriptDocument:GetSelection():Tuple
戻り値

GetSelectionEnd
プラグインのセキュリティ
ScriptDocument:GetSelectionEnd():Tuple
戻り値
コードサンプル
ScriptDocument:GetSelectionStart() と :GetSelectionEnd()
--!nocheck
-- スクリプトが開いている間に、コマンドバーで次のコードを実行します
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(`選択開始: 行 {startLine}, 文字 {startCharacter}`)
print(`選択終了: 行 {endLine}, 文字 {endCharacter}`)
else
print("スクリプトは開いていません")
end

GetSelectionStart
プラグインのセキュリティ
ScriptDocument:GetSelectionStart():Tuple
戻り値
コードサンプル
ScriptDocument:GetSelectionStart() と :GetSelectionEnd()
--!nocheck
-- スクリプトが開いている間に、コマンドバーで次のコードを実行します
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(`選択開始: 行 {startLine}, 文字 {startCharacter}`)
print(`選択終了: 行 {endLine}, 文字 {endCharacter}`)
else
print("スクリプトは開いていません")
end

GetText
プラグインのセキュリティ
ScriptDocument:GetText(
startLine:number?, startCharacter:number?, endLine:number?, endCharacter:number?
パラメータ
startLine:number?
既定値: "nil"
startCharacter:number?
既定値: "nil"
endLine:number?
既定値: "nil"
endCharacter:number?
既定値: "nil"
戻り値
コードサンプル
スクリプトドキュメント:GetText()
--!nocheck
-- スクリプトが開いている状態でコマンドバーに以下のコードを実行します
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(`スクリプトの内容: {text}`)
else
print("スクリプトは開いていません")
end

GetViewport
プラグインのセキュリティ
ScriptDocument:GetViewport():Tuple
戻り値
コードサンプル
ScriptDocument:GetViewport
--!nocheck
-- スクリプトが開いている間にコマンドバーで次のコードを実行します
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(`現在の表示行は {firstLine} から {lastLine} です`)
else
print("スクリプトが開いていません")
end

HasSelectedText
プラグインのセキュリティ
ScriptDocument:HasSelectedText():boolean
戻り値
コードサンプル
ScriptDocument:HasSelectedText() と :GetSelectedText()
--!nocheck
-- スクリプトが開いている間に、コマンドバーで以下のコードを実行してください
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(`現在選択されているテキスト: {selectedText}`)
else
print("現在選択されているテキストはありません")
end
end)
else
print("スクリプトは開いていません")
end

IsCommandBar
プラグインのセキュリティ
ScriptDocument:IsCommandBar():boolean
戻り値
コードサンプル
ScriptDocument:IsCommandBar()
---!nocheck
-- コマンドバーで次のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("コマンドバーのドキュメント:", document)
end
end

MultiEditTextAsync
イールド
プラグインのセキュリティ
ScriptDocument:MultiEditTextAsync(edits:{any}):Tuple
パラメータ
edits:{any}
戻り値

RequestSetSelectionAsync
イールド
プラグインのセキュリティ
ScriptDocument:RequestSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
パラメータ
cursorLine:number
cursorCharacter:number
anchorLine:number?
既定値: "nil"
anchorCharacter:number?
既定値: "nil"
戻り値
コードサンプル
スクリプトドキュメント:RequestSetSelectionAsync()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
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 cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- テキストの全行を強制的に選択
local success, err = scriptDocument:RequestSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("選択が設定されました!")
else
print(`選択の設定に失敗しました: {err}`)
end
else
print("スクリプトが開いていません")
end

イベント
SelectionChanged
プラグインのセキュリティ
ScriptDocument.SelectionChanged(
positionLine:number, positionCharacter:number, anchorLine:number, anchorCharacter:number
パラメータ
positionLine:number
positionCharacter:number
anchorLine:number
anchorCharacter:number
コードサンプル
ScriptDocument.SelectionChanged と ScriptDocument:GetLine()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
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(`選択された: 行 {positionLine}, 文字 {positionCharacter}`)
print(`アンカー: 行 {anchorLine}, 文字 {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`選択された行のテキスト: {lineText}`)
end)
else
print("スクリプトが開いていません")
end

ViewportChanged
プラグインのセキュリティ
ScriptDocument.ViewportChanged(
startLine:number, endLine:number
パラメータ
startLine:number
endLine:number
コードサンプル
ScriptDocument.ViewportChanged への接続
--!nocheck
--[[
実行するには:
1. 出力ビューが開いていることを確認します
2. コマンドバーで以下のコードを実行します
3. 開いているスクリプトウィンドウで上下にスクロールします
ViewportChanged イベントからの印刷文は出力に表示されます
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- 複数行にわたるテキストを作成
local dummyText = string.rep("-- ダミーテキスト\n", 60)
-- ダミーテキストを含むスクリプトを作成し、それを開く
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`スクリプトのオープンに失敗しました: {err}`)
return
end
-- 開かれたスクリプトへの参照を取得
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`スクリプトのビューポートが変更されました - 開始行: {startLine}, 終了行: {endLine}`)
end
-- 更新されたビューポートの開始行と終了行を印刷する上記の関数に ViewportChanged イベントを接続
scriptDocument.ViewportChanged:Connect(onViewportChanged)

©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。