Class
ScriptContext
NotCreatableServiceNotReplicated
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#
| EnableCoverage | Marks an instance and its descendant scripts for code-coverage tracking.
Requires PluginOrOpenCloud security. |
| GetCoverageStats | Returns code-coverage statistics for scripts marked by
EnableCoverage(). Requires
PluginOrOpenCloud security. |
| SetTimeout | Limits 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().
| Name | Type | Default | Description |
|---|---|---|---|
instance | Instance | The 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 aScriptfield and aGetHitsfunction 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.
| Name | Type | Default | Description |
|---|---|---|---|
seconds | double | The 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#
| Error | Fired 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()).
| Name | Type | Default | Description |
|---|---|---|---|
message | string | The error message describing what went wrong. | |
stackTrace | string | The call stack at the point the error occurred, formatted as a string. | |
script | Instance | The script in which the error occurred. |
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild