7 min read

Source: Roblox Creator Hub · CC BY 4.0 · View source · Code samples: MIT Imported 2026-10-03. Formatting adapted for this site.

ScriptContext

Inherits from: Instance → Object

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

Inherits from: Instance

Memory category: Instances

Tags: NotCreatable, Service, NotReplicated

Methods

NameType / ReturnsDescription
ScriptContext:EnableCoverage()Marks an instance and its descendant scripts for code-coverage tracking. Requires PluginOrOpenCloud security.
ScriptContext:GetCoverageStatsArrayReturns code-coverage statistics for scripts marked by EnableCoverage(). Requires PluginOrOpenCloud security.
ScriptContext:SetTimeout()Limits how long a script is allowed to run without yielding.

Inherited from Instance

NameType / ReturnsDescription
Instance:AddTag()Applies a tag to the instance.
Instance:childrenInstancesReturns an array of the object's children.
Instance:ClearAllChildren()This method destroys all of an instance's children.
Instance:CloneInstanceCreate a copy of an instance and all its descendants, ignoring instances that are not Archivable.
Instance:cloneInstance
Instance:Destroy()Sets the Instance.Parent property to nil, locks the Instance.Parent property, disconnects all connections, and calls Destroy() on all children.
Instance:destroy()
Instance:FindFirstAncestorInstance?Returns the first ancestor of the Instance whose Instance.Name is equal to the given name.
Instance:FindFirstAncestorOfClassInstance?Returns the first ancestor of the Instance whose Object.ClassName is equal to the given className.
Instance:FindFirstAncestorWhichIsAInstance?Returns the first ancestor of the Instance for whom Object:IsA() returns true for the given className.
Instance:FindFirstChildInstance?Returns the first child of the Instance found with the given name.
Instance:findFirstChildInstance
Instance:FindFirstChildOfClassInstance?Returns the first child of the Instance whose ClassName is equal to the given class name.
Instance:FindFirstChildWhichIsAInstance?Returns the first child of the Instance for whom Object:IsA() returns true for the given className.
Instance:FindFirstDescendantInstance?Returns the first descendant found with the given Instance.Name.
Instance:GetActorActor?Returns the Actor associated with the Instance, if any.
Instance:GetAttributeVariantReturns the value which has been assigned to the given attribute name.
Instance:GetAttributeChangedSignalRBXScriptSignalReturns an event that fires when the given attribute changes.
Instance:GetAttributesDictionaryReturns a dictionary of the instance's attributes.
Instance:GetChildrenInstancesReturns an array containing all of the instance's children.
Instance:getChildrenInstances
Instance:GetDebugIdstringReturns a coded string of the debug ID used internally by Roblox.
Instance:GetDescendantsInstancesReturns an array containing all of the descendants of the instance.
Instance:GetFullNamestringReturns a string describing the instance's ancestry.
Instance:GetStyledVariantReturns the styled or explicitly modified value of the specified property, or else the default property value if it hasn't been styled/modified.
Instance:GetStyledPropertyChangedSignalRBXScriptSignalReturns an event that fires when the given style property changes on the instance.
Instance:GetTagsArrayGets an array of all tags applied to the instance.
Instance:HasTagbooleanCheck whether the instance has a given tag.
Instance:IsAncestorOfbooleanReturns true if an Instance is an ancestor of the given descendant.
Instance:IsDescendantOfbooleanReturns true if an Instance is a descendant of the given ancestor.
Instance:isDescendantOfboolean
Instance:IsPropertyModifiedbooleanReturns true if the value stored in the specified property is not equal to the code-instantiated default.
Instance:QueryDescendantsInstancesReturns an array containing all descendants of the instance that match the selector string.
Instance:Remove()Sets the object's Parent to nil, and does the same for all its descendants.
Instance:remove()
Instance:RemoveTag()Removes a tag from the instance.
Instance:ResetPropertyToDefault()Resets a property to its default value.
Instance:SetAttribute()Sets the attribute with the given name to the given value.
Instance:WaitForChildInstanceReturns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does.

Inherited from Object

NameType / ReturnsDescription
Object:GetPropertyChangedSignalRBXScriptSignalGet an event that fires when a given property of the object changes.
Object:IsAbooleanReturns true if an object's class matches or inherits from a given class.
Object:isAboolean

ScriptContext:EnableCoverage

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

Parameters

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

Returns

TypeDescription
()
FieldValue
securityNone
thread safetyUnsafe
capabilities["PluginOrOpenCloud"]

ScriptContext:GetCoverageStats

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

TypeDescription
ArrayAn array of per-script coverage tables, each with a Script field and a GetHits function for retrieving line and function hit counts.
FieldValue
securityNone
thread safetyUnsafe
capabilities["PluginOrOpenCloud"]

ScriptContext:SetTimeout

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.

Parameters

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

TypeDescription
()
FieldValue
securityPluginSecurity
thread safetyUnsafe

Events

NameType / ReturnsDescription
ScriptContext.ErrorFired when an error occurs.

Inherited from Instance

NameType / ReturnsDescription
Instance.AncestryChangedFires when the Instance.Parent property of this object or one of its ancestors is changed.
Instance.AttributeChangedFires whenever an attribute is changed on the Instance.
Instance.ChildAddedFires after an object is parented to this Instance.
Instance.childAdded
Instance.ChildRemovedFires after a child is removed from this Instance.
Instance.DescendantAddedFires after a descendant is added to the Instance.
Instance.DescendantRemovingFires immediately before a descendant of the Instance is removed.
Instance.DestroyingFires immediately before (or is deferred until after) the instance is destroyed via Instance:Destroy().
Instance.StyledPropertiesChangedFires whenever any style property is changed on the instance, including when a property is set to nil.

Inherited from Object

NameType / ReturnsDescription
Object.ChangedFires immediately after a property of the object changes, with some limitations.

ScriptContext.Error

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

Parameters

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.
FieldValue
securityNone
capabilities["Logging"]

Code samples: View on Creator Hub (ScriptContext-Error1).

Properties

Inherited from Instance

NameType / ReturnsDescription
Instance.ArchivablebooleanDetermines if an Instance and its descendants can be cloned using Instance:Clone(), and can be saved/published.
Instance.archivableboolean
Instance.CapabilitiesSecurityCapabilitiesThe set of capabilities allowed to be used for scripts inside this container.
Instance.IsInSandboxbooleanIndicates whether the instance is inside a sandboxed container.
Instance.NamestringA non-unique identifier of the Instance.
Instance.ParentInstanceDetermines the hierarchical parent of the Instance.
Instance.PredictionModePredictionModeReflects the client-side prediction mode applied to the instance under server-authoritative physics.
Instance.RobloxLockedbooleanA deprecated property that used to protect CoreGui objects.
Instance.SandboxedbooleanWhen enabled, the instance can only access abilities in its Capabilities list.
Instance.UniqueIdUniqueIdA unique identifier for the instance.

Inherited from Object

NameType / ReturnsDescription
Object.ClassNamestringA read-only string representing the class this Object belongs to.
Object.classNamestring