# ScriptContext

Roblox Engine API class from Roblox Studio 0.744.0.7441077 (version-7aaa6838d36c4448).

- Inherits from, nearest first: [Instance](https://rapi.sleaze.dev/classes/Instance.md), [Object](https://rapi.sleaze.dev/classes/Object.md)
- Tags: Not creatable, Not replicated, Service
- Memory category: Instances
- HTML page: https://rapi.sleaze.dev/classes/ScriptContext/
- Roblox documentation: https://create.roblox.com/docs/reference/engine/classes/ScriptContext

A service that manages the execution of all [`BaseScript`](https://rapi.sleaze.dev/classes/BaseScript.md) objects.

## Properties

### ScriptsDisabled

```luau
ScriptContext.ScriptsDisabled: boolean = false
```

- Tags: Hidden, Local user security

## Methods

### AddCoreScriptLocal

```luau
ScriptContext:AddCoreScriptLocal(name: string, parent: Instance)
```

- Tags: Roblox script security

### CompressLuaApp

```luau
ScriptContext:CompressLuaApp()
```

- Tags: Roblox script security

### EnableCoverage

```luau
ScriptContext:EnableCoverage(instance: Instance)
```

- Tags: Capabilities: PluginOrOpenCloud

Marks an instance and its descendant scripts for code-coverage tracking. Requires `PluginOrOpenCloud` security.

Parameters:

- `instance`: The instance to track; coverage is recorded for this instance and every script descended from it.

### GetCoverageStats

```luau
ScriptContext:GetCoverageStats(): { any }
```

- Tags: Capabilities: PluginOrOpenCloud

Returns code-coverage statistics for scripts marked by [`EnableCoverage()`](https://rapi.sleaze.dev/classes/ScriptContext.md). Requires `PluginOrOpenCloud` security.

Returns: An array of per-script coverage tables, each with a [`Script`](https://rapi.sleaze.dev/classes/Script.md) field and a `GetHits` function for retrieving line and function hit counts.

### GetLuauHeapInstanceReferenceReport

```luau
ScriptContext:GetLuauHeapInstanceReferenceReport(target: string): { [string]: any }
```

- Tags: Custom Lua state, Roblox script security

### GetLuauHeapMemoryReport

```luau
ScriptContext:GetLuauHeapMemoryReport(target: string): { [string]: any }
```

- Tags: Custom Lua state, Roblox script security

### ReportLuaRequireCount

```luau
ScriptContext:ReportLuaRequireCount()
```

- Tags: Roblox script security

### SetTimeout

```luau
ScriptContext:SetTimeout(seconds: number)
```

- Tags: Plugin security

Limits how long a script is allowed to run without yielding.

Parameters:

- `seconds`: The maximum time, in seconds, that a script may run between yields before the watchdog interrupts it. A value of `0` disables the timeout.

## Events

### Error

```luau
ScriptContext.Error: RBXScriptSignal<(message: string, stackTrace: string, script: Instance)>
```

- Tags: Capabilities: Logging

Fired when an error occurs.

### ErrorDetailed

```luau
ScriptContext.ErrorDetailed: RBXScriptSignal<(message: string, stackTrace: string, script: Instance, details: string, securityLevel: number, messageId: string)>
```

- Tags: Roblox script security

## Inherited members

- From [Instance](https://rapi.sleaze.dev/classes/Instance.md): `Archivable`, `archivable`, `Attributes`, `AttributesReplicate`, `AttributesSerialize`, `HistoryId`, `Name`, `Parent`, `PredictionMode`, `PropertyStatusStudio`, `RobloxLocked`, `SerializedOverrides`, `SourceAssetId`, `Tags`, `UniqueId`, `numExpectedDirectChildren`, `DataCost`, `Capabilities`, `DefinesCapabilities`, `IsInSandbox`, `Sandboxed`, `AddTag`, `ClearAllChildren`, `Clone`, `Destroy`, `FindFirstAncestor`, `FindFirstAncestorOfClass`, `FindFirstAncestorWhichIsA`, `FindFirstChild`, `FindFirstChildOfClass`, `FindFirstChildWhichIsA`, `FindFirstDescendant`, `GetActor`, `GetAttribute`, `GetAttributeChangedSignal`, `GetAttributes`, `GetChildren`, `GetDebugId`, `GetDescendants`, `GetFullName`, `GetStyled`, `GetStyledPropertyChangedSignal`, `GetTags`, `HasTag`, `IsAncestorOf`, `IsDescendantOf`, `IsPropertyModified`, `QueryDescendants`, `RemoveTag`, `ResetPropertyToDefault`, `SetAttribute`, `WaitForChild`, `Remove`, `children`, `clone`, `destroy`, `findFirstChild`, `getChildren`, `isDescendantOf`, `remove`, `AncestryChanged`, `AttributeChanged`, `ChildAdded`, `ChildRemoved`, `DescendantAdded`, `DescendantRemoving`, `Destroying`, `StyledPropertiesChanged`, `childAdded`
- From [Object](https://rapi.sleaze.dev/classes/Object.md): `ClassName`, `className`, `GetPropertyChangedSignal`, `IsA`, `isA`, `Changed`
