Reference API Roblox

Engine API

Website

Related

Reference API Roblox

ScriptContext

A service that manages the execution of all BaseScript objects.

This class is not replicated. Its interface does not cross the network boundary.
This class is not creatable. Instances of this class cannot be created with Instance.new.
This class is a service. It is a singleton that may be acquired with GetService.
Tags: [NotCreatable, Service, NotReplicated]

Member index 11

HistoryMember
573AddCoreScriptLocal(name: string, parent: Instance): null
648CompressLuaApp(): null
715EnableCoverage(instance: Instance): null
715GetCoverageStats(): Array
607GetLuauHeapInstanceReferenceReport(target: string): Dictionary
607GetLuauHeapMemoryReport(target: string): Dictionary
638ReportLuaRequireCount(): null
573SetTimeout(seconds: double): null
462Error(message: string, stackTrace: string, script: Instance)
660ErrorDetailed(message: string, stackTrace: string, script: Instance, details: string, securityLevel: int, messageId: string)
inherited from Instance
731Archivable: bool
731Capabilities: SecurityCapabilities
731IsInSandbox: bool
731Name: string
731Parent: Instance
731PredictionMode: PredictionMode
731Sandboxed: bool
731UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
707GetDescendants(): Instances
486GetFullName(): string
706GetStyled(name: string, selector: string?): Variant
657GetStyledPropertyChangedSignal(property: string): RBXScriptSignal
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
664IsPropertyModified(property: string): bool
698QueryDescendants(selector: string): Instances
573Remove(): null
576RemoveTag(tag: string): null
664ResetPropertyToDefault(property: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
731children(): Instances
731clone(): Instance
731destroy(): null
731findFirstChild(name: string, recursive: bool = false): Instance
731getChildren(): Instances
731isDescendantOf(ancestor: Instance): bool
731remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
657StyledPropertiesChanged()
731childAdded(child: Instance)
inherited from Object
731ClassName: string
731className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
731isA(className: string): bool
647Changed(property: string)

Removed member index 23

HistoryMember
214GarbageCollectionFrequency: int
214GarbageCollectionLimit: int
272AddCoreScript(assetId: int, parent: Instance, name: string): void
273AddStarterScript(assetId: int): void
678ClearScriptProfilingData(): null
678DeserializeScriptProfilerString(jsonString: string?): Dictionary
310GetHeapStats(clearHighwaterMark: bool = true): Tuple
678GetScriptProfilingData(): string
310GetScriptStats(): Array
168LibraryRegistrationComplete(): void
168RegisterDevelopmentLibrary(libraryName: string, scriptInstance: Instance): void
168RegisterLibrary(libraryName: string, assetId: string): void
168RegisterRobloxLibrary(libraryName: string, assetId: string): void
401ResetCoverageCollection(): void
678SaveScriptProfilingData(jsonString: string, filename: string): string
310SetCollectScriptStats(enable: bool = false): void
400SetCoverageFilter(callback: Function): void
401StartCoverageCollection(): void
678StartScriptProfiling(frequency: int?): null
401StopCoverageCollection(): void
678StopScriptProfiling(): string
310CamelCaseViolation(object: Instance, member: string, script: Instance)
76NonScriptableAccess(property: string, script: Instance)

Description

This service controls all BaseScript objects. Most of the properties and methods of this service are locked for internal use.

History 104

Members 11

AddCoreScriptLocal

Parameters (2)
namestring
parentInstance
Returns (1)
null

History 3

CompressLuaApp

Parameters (0)
No parameters.
Returns (1)
null

History 1

EnableCoverage

Parameters (1)
instanceInstance
Returns (1)
null

Requires PluginOrOpenCloud security; not callable from game scripts. Registers instance as a coverage root so the engine records per-line and per-function execution coverage for instance and every script descended from it. Retrieve the recorded data with ScriptContext:GetCoverageStats().

History 1

Error

Parameters (3)
messagestring
stackTracestring
scriptInstance

Fires when an unhandled error occurs while running a script, reporting the error to any listening code. The engine raises this event from its error-reporting path when a thread terminates with an error, passing the error message, a formatted stackTrace string, and the script that was running.

This event does not fire for errors raised by the watchdog when a script exceeds its execution-time limit (see ScriptContext:SetTimeout()).

History 3

  • 462 Change ThreadSafety of Error from to Unsafe
  • 135 Change Security of Error from RobloxPlaceSecurity to None
  • 47 Add Error

ErrorDetailed

Parameters (6)
messagestring
stackTracestring
scriptInstance
detailsstring
securityLevelint
messageIdstring

History 4

GetCoverageStats

Parameters (0)
No parameters.
Returns (1)
Array

Requires PluginOrOpenCloud security; not callable from experience scripts. Returns an array of coverage results, one entry per tracked script. Each entry is a table with a Script field (the script Instance) and a GetHits() function. Calling GetHits() returns two arrays: per-line hit counts, where -1 marks a line that was never executed or was excluded, and per-function records containing each function's Name, Line, and Hits.

Like ScriptContext:EnableCoverage(), this method raises an error if coverage collection is not enabled.

History 3

GetLuauHeapInstanceReferenceReport

Parameters (1)
targetstring
Returns (1)
Dictionary
This function has a custom internal state. It may behave in a non-standard way.

History 1

Tags: [CustomLuaState]

GetLuauHeapMemoryReport

Parameters (1)
targetstring
Returns (1)
Dictionary
This function has a custom internal state. It may behave in a non-standard way.

History 1

Tags: [CustomLuaState]

ReportLuaRequireCount

Parameters (0)
No parameters.
Returns (1)
null

History 1

SetTimeout

Parameters (1)
secondsdouble
Returns (1)
null

Sets the watchdog time limit that the engine applies to running scripts. The value becomes the per-resumption execution budget: if a thread runs for longer than seconds since it was last resumed without yielding, the watchdog aborts it with the runtime error Script timeout: exhausted allowed execution time.

The timeout defaults to 0, which disables the watchdog so that scripts may run without any time limit. Call this method with a positive value to enable enforcement, or pass 0 to turn it back off.

History 4

Removed members 23

AddCoreScript

Parameters (3)
assetIdint
parentInstance
namestring
Returns (1)
void

History 2

AddStarterScript

Parameters (1)
assetIdint
Returns (1)
void

History 4

CamelCaseViolation

Parameters (3)
objectInstance
memberstring
scriptInstance

History 2

ClearScriptProfilingData

Parameters (0)
No parameters.
Returns (1)
null

History 3

DeserializeScriptProfilerString

Parameters (1)
jsonStringstring?
Returns (1)
Dictionary
This function has a custom internal state. It may behave in a non-standard way.

History 3

Tags: [CustomLuaState]

GarbageCollectionFrequency

TypeDefault
int

History 4

GarbageCollectionLimit

TypeDefault
int

History 4

GetHeapStats

Parameters (1)Default
clearHighwaterMarkbooltrue
Returns (1)
Tuple

History 3

GetScriptProfilingData

Parameters (0)
No parameters.
Returns (1)
string

History 2

GetScriptStats

Parameters (0)
No parameters.
Returns (1)
Array

History 4

LibraryRegistrationComplete

Parameters (0)
No parameters.
Returns (1)
void

History 3

NonScriptableAccess

Parameters (2)
propertystring
scriptInstance

History 2

RegisterDevelopmentLibrary

Parameters (2)
libraryNamestring
scriptInstanceInstance
Returns (1)
void

History 3

RegisterLibrary

Parameters (2)
libraryNamestring
assetIdstring
Returns (1)
void

History 3

RegisterRobloxLibrary

Parameters (2)
libraryNamestring
assetIdstring
Returns (1)
void

History 3

ResetCoverageCollection

Parameters (0)
No parameters.
Returns (1)
void

History 2

SaveScriptProfilingData

Parameters (2)
jsonStringstring
filenamestring
Returns (1)
string

History 5

SetCollectScriptStats

Parameters (1)Default
enableboolfalse
Returns (1)
void

History 3

SetCoverageFilter

Parameters (1)
callbackFunction
Returns (1)
void

History 2

StartCoverageCollection

Parameters (0)
No parameters.
Returns (1)
void

History 2

StartScriptProfiling

Parameters (1)
frequencyint?
Returns (1)
null

History 4

StopCoverageCollection

Parameters (0)
No parameters.
Returns (1)
void

History 2

StopScriptProfiling

Parameters (0)
No parameters.
Returns (1)
string

History 5

Settings