Roblox UtilitiesDevlHub Roblox Documentation

Class

ScriptContext

NotCreatableServiceNotReplicated
Inherits
Instance › Object
Memory category
Instances

A service that manages the execution of all BaseScript objects.

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

Methods 3#

EnableCoverageMarks an instance and its descendant scripts for code-coverage tracking. Requires PluginOrOpenCloud security.
GetCoverageStatsReturns code-coverage statistics for scripts marked by EnableCoverage(). Requires PluginOrOpenCloud security.
SetTimeoutLimits how long a script is allowed to run without yielding.PluginSecurity security

EnableCoverage(instance: Instance): ()#

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().

NameTypeDefaultDescription
instanceInstanceThe instance to track; coverage is recorded for this instance and every script descended from it.
Returns
  • ()

GetCoverageStats(): 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.

Returns
  • Array — An array of per-script coverage tables, each with a Script field and a GetHits function for retrieving line and function hit counts.

SetTimeout(seconds: double): ()#

PluginSecurity security

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.

NameTypeDefaultDescription
secondsdoubleThe maximum time, in seconds, that a script may run between yields before the watchdog interrupts it. A value of 0 disables the timeout.
Returns
  • ()

Events 1#

ErrorFired when an error occurs.

Error(message: string, stackTrace: string, script: Instance)#

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()).

NameTypeDefaultDescription
messagestringThe error message describing what went wrong.
stackTracestringThe call stack at the point the error occurred, formatted as a string.
scriptInstanceThe script in which the error occurred.

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed