Service · inherits Instance
ScriptContext
A service that manages the execution of all BaseScript objects.
About ScriptContext
This service controls all BaseScript objects. Most of the properties
and methods of this service are locked for internal use.
Methods 3
EnableCoverage
(instance: Instance) → ()Marks an instance and its descendant scripts for code-coverage tracking. RequiresPluginOrOpenCloudsecurity.Requires
PluginOrOpenCloudsecurity; not callable from game scripts. Registersinstanceas a coverage root so the engine records per-line and per-function execution coverage forinstanceand every script descended from it. Retrieve the recorded data withScriptContext.GetCoverageStats.GetCoverageStats
() → ArrayReturns code-coverage statistics for scripts marked byEnableCoverage(). RequiresPluginOrOpenCloudsecurity.Requires
PluginOrOpenCloudsecurity; not callable from experience scripts. Returns an array of coverage results, one entry per tracked script. Each entry is a table with aScriptfield (the scriptInstance) and aGetHits()function. CallingGetHits()returns two arrays: per-line hit counts, where-1marks a line that was never executed or was excluded, and per-function records containing each function'sName,Line, andHits.Like
ScriptContext.EnableCoverage, this method raises an error if coverage collection is not enabled.SetTimeout
(seconds: double) → ()PluginLimits how long a script is allowed to run without yielding.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
secondssince it was last resumed without yielding, the watchdog aborts it with the runtime errorScript 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 pass0to turn it back off.
Events 1
Error
ScriptContext.Error:Connect(function(message, stackTrace, script))Fired when an error occurs.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 formattedstackTracestring, and thescriptthat was running.This event does not fire for errors raised by the watchdog when a script exceeds its execution-time limit (see
ScriptContext.SetTimeout).
ScriptContext also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.