Skip to content
Roblox API Reference

ScriptDocument

Represents the ephemeral state of an open document in the Studio Script Editor, providing APIs for reading and editing code.
  • Not creatable
  • Not replicated
Memory category
Instances
Own members
24
Inherited members
75
Subclasses
0
Siblings
608

Properties23

Inherited fromObject2

Property categoryData

Inherited fromInstance21

Property categoryBehavior

Property categoryData

Property categoryPermissions

Methods64

Inherited fromObject3
  • Get an event that fires when a given property of the object changes.
    Parameters
    ParameterDescription
    property: string
    The property to connect to.
    Returns
    TypeDescription
    RBXScriptSignal
    A signal that fires whenever the property changes.
  • Object:IsA(className: string): boolean
    Returns true if an object's class matches or inherits from a given class.
    • Custom Lua state
    • Thread safe
    Parameters
    ParameterDescription
    className: string
    The class against which the Object's class will be checked. Case-sensitive.
    Returns
    TypeDescription
    boolean
    Describes whether the Object's class matched or is a subclass of the given class.
  • Object:isA(className: string): boolean
    Deprecated: This deprecated function is a variant of Object:IsA() which should be used instead.
    • Deprecated
    • Custom Lua state
    Parameters
    Parameter
    className: string
    Returns
    Type
    boolean

    Use IsA instead.

Inherited fromInstance39
Defined byScriptDocument22
  • ScriptDocument:AddReadOnlyReasonsAsync(reasons: { any })
    • Yields
    • Plugin security
    Parameters
    Parameter
    reasons: { any }
  • ScriptDocument:CloseAsync(): ...any
    Requests that the editor associated with this document close. Yields the current thread until the editor responds to the request.
    • Yields
    • Plugin security
    Returns
    TypeDescription
    ...any
    A tuple where the first element is true if the editor closed successfully, or false followed by a string describing the failure reason.
  • ScriptDocument:EditTextAsync(newText: string,startLine: number,startCharacter: number,endLine: number,endCharacter: number,): ...any
    Replaces the text in the specified range from (startLine, startColumn) to (endLine, endColumn) with newText.
    • Yields
    • Plugin security
    Parameters
    ParameterDescription
    newText: string
    The replacement string to insert into the specified range.
    startLine: number
    The 1-indexed line number where the replacement range begins.
    startCharacter: number
    The 1-indexed UTF-8 byte offset within startLine where the replacement range begins.
    endLine: number
    The 1-indexed line number where the replacement range ends (exclusive).
    endCharacter: number
    The 1-indexed UTF-8 byte offset within endLine where the replacement range ends (exclusive).
    Returns
    TypeDescription
    ...any
    A tuple where the first element is true if the edit was applied successfully, or false followed by a string describing the failure reason.
  • ScriptDocument:ForceSetSelectionAsync(cursorLine: number,cursorCharacter: number,anchorLine: number? = nil,anchorCharacter: number? = nil,): ...any
    Asks the editor to set its cursor selection to the argument values.
    • Yields
    • Plugin security
    Parameters
    ParameterDescription
    cursorLine: number
    The 1-indexed line number for the cursor position.
    cursorCharacter: number
    The 1-indexed UTF-8 byte offset within the line for the cursor position.
    anchorLine: number? = nil
    The 1-indexed line number for the anchor position. Defaults to cursorLine if not provided.
    anchorCharacter: number? = nil
    The 1-indexed UTF-8 byte offset within the line for the anchor position. Defaults to cursorCharacter if not provided.
    Returns
    TypeDescription
    ...any
    A tuple where the first element is true if the cursor was updated, or false followed by a string explaining why the update was declined.
  • ScriptDocument:GetInternalUri(): string
    • Roblox script security
    Returns
    Type
    string
  • ScriptDocument:GetLine(lineIndex: number? = nil): string
    Returns the text of the specified line. When no argument is provided, returns the line of the current cursor position.
    • Plugin security
    Parameters
    ParameterDescription
    lineIndex: number? = nil
    The 1-indexed line number to retrieve. Defaults to the current cursor line if not provided.
    Returns
    TypeDescription
    string
    The text content of the specified line as a string.
  • ScriptDocument:GetLineCount(): number
    Returns the number of lines in the document.
    • Plugin security
    Returns
    TypeDescription
    number
    The total number of lines in the document.
  • ScriptDocument:GetReadOnlyReasons(): { any }
    • Plugin security
    Returns
    Type
    { any }
  • ScriptDocument:GetScript(): LuaSourceContainer
    Returns the underlying LuaSourceContainer instance, if one exists, otherwise nil.
    • Plugin security
    Returns
    TypeDescription
    LuaSourceContainer
    The LuaSourceContainer that the document is editing, or nil if the document does not represent a script instance in the place (e.g. the Command Bar is not a real script instance).
  • ScriptDocument:GetSelectedText(): string
    Gets the text selected in the editor, or an empty string if there is no selection.
    • Plugin security
    Returns
    TypeDescription
    string
    The currently selected text as a string, or an empty string if nothing is selected.
  • ScriptDocument:GetSelection(): ...any
    Returns the last known selection of the Script Editor in the format: CursorLine, CursorChar, AnchorLine, AnchorChar. If the Script Editor has no selection, CursorLine == AnchorLine and CursorChar == AnchorChar.
    • Plugin security
    Returns
    TypeDescription
    ...any
    CursorLine, CursorChar, AnchorLine, AnchorChar.
  • ScriptDocument:GetSelectionEnd(): ...any
    Gets the larger of the cursor position and anchor. If the editor has no selection, they are the same value.
    • Plugin security
    Returns
    TypeDescription
    ...any
    A tuple of (line, character) representing the larger of the cursor and anchor positions, both 1-indexed.
  • ScriptDocument:GetSelectionStart(): ...any
    Gets the smaller of the cursor position and anchor. If the editor has no selection, they are the same value.
    • Plugin security
    Returns
    TypeDescription
    ...any
    A tuple of (line, character) representing the smaller of the cursor and anchor positions, both 1-indexed.
  • ScriptDocument:GetText(startLine: number? = nil,startCharacter: number? = nil,endLine: number? = nil,endCharacter: number? = nil,): string
    Returns text from the open editor.
    • Plugin security
    Parameters
    ParameterDescription
    startLine: number? = nil
    The 1-indexed line number where the text range begins. Optional; omit all arguments to get the entire document.
    startCharacter: number? = nil
    The 1-indexed UTF-8 byte offset within startLine where the text range begins.
    endLine: number? = nil
    The 1-indexed line number where the text range ends (exclusive). Optional; omit to read from startLine/startCharacter to the end of the document.
    endCharacter: number? = nil
    The 1-indexed UTF-8 byte offset within endLine where the text range ends (exclusive).
    Returns
    TypeDescription
    string
    The text content within the specified range as a string.
  • ScriptDocument:GetViewport(): ...any
    Returns the currently displayed line numbers in the editor change.
    • Plugin security
    Returns
    TypeDescription
    ...any
    A tuple of (startLine, endLine) representing the 1-indexed range of lines currently visible in the editor.
  • ScriptDocument:HasSelectedText(): boolean
    Returns whether or not the editor has any text selected.
    • Plugin security
    Returns
    TypeDescription
    boolean
    true if the editor has a non-empty text selection, false otherwise.
  • ScriptDocument:IsCommandBar(): boolean
    Returns true if the ScriptDocument represents the Command bar.
    • Plugin security
    Returns
    TypeDescription
    boolean
    true if this document represents the Command bar, false otherwise.
  • ScriptDocument:IsReadOnly(): boolean
    • Plugin security
    Returns
    Type
    boolean
  • ScriptDocument:MultiEditTextAsync(edits: { any }): ...any
    Applies a batch of text edits to the document as a single atomic operation. Yields the current thread until the editor responds.
    • Yields
    • Plugin security
    Parameters
    ParameterDescription
    edits: { any }
    An array of tables, each describing a text replacement with fields NewText, StartLine, StartCharacter, EndLine, and EndCharacter.
    Returns
    TypeDescription
    ...any
    A tuple where the first element is true if all edits were applied successfully, or false followed by a string describing the failure reason.
  • ScriptDocument:RemoveReadOnlyReasonsAsync(reasons: { any })
    • Yields
    • Plugin security
    Parameters
    Parameter
    reasons: { any }
  • ScriptDocument:RequestSetSelectionAsync(cursorLine: number,cursorCharacter: number,anchorLine: number? = nil,anchorCharacter: number? = nil,): ...any
    Asks the editor to set its cursor selection to the argument values.
    • Yields
    • Plugin security
    Parameters
    ParameterDescription
    cursorLine: number
    The 1-indexed line number for the cursor position.
    cursorCharacter: number
    The 1-indexed UTF-8 byte offset within the line for the cursor position.
    anchorLine: number? = nil
    The 1-indexed line number for the anchor position. Defaults to cursorLine if not provided.
    anchorCharacter: number? = nil
    The 1-indexed UTF-8 byte offset within the line for the anchor position. Defaults to cursorCharacter if not provided.
    Returns
    TypeDescription
    ...any
    A tuple where the first element is true if the cursor was updated, or false followed by a string explaining why the update was declined.
  • ScriptDocument:ReviewableTextEditsAsync(changes: { any }): ...any
    Applies a batch of line-based text edits that appear in the editor as reviewable inline diffs, allowing users to accept or reject each change.
    • Yields
    • Plugin security
    Parameters
    ParameterDescription
    changes: { any }
    An array of tables, each with a Text field (the replacement string), a StartLine field (1-indexed line to insert or begin replacing at), and an optional EndLine field (1-indexed last line to replace, inclusive).
    Returns
    TypeDescription
    ...any
    A tuple where the first element is true if the edits were applied successfully, or false followed by a string describing the failure reason.

Events12

Inherited fromObject1
Inherited fromInstance9
Defined byScriptDocument2
  • ScriptDocument.SelectionChanged: RBXScriptSignal<(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number,)>
    Fires when the ScriptDocument changes, including immediately after a text change.
    • Plugin security
    Parameters
    Parameter
    positionLine: number
    positionCharacter: number
    anchorLine: number
    anchorCharacter: number
  • ScriptDocument.ViewportChanged: RBXScriptSignal<(startLine: number,endLine: number,)>
    Fires when the displayed line numbers in the editor change.
    • Plugin security
    Parameters
    Parameter
    startLine: number
    endLine: number