Reference API Roblox

Engine API

Website

Related

Reference API Roblox

RunService

Service responsible for all runtime activity and progression of time.

This class is not replicated. Its interface does not cross the network boundary.
This class is not creatable. Instances of this class cannot be created with Instance.new.
This class is a service. It is a singleton that may be acquired with GetService.
Tags: [NotCreatable, Service, NotReplicated]

Member index 29

HistoryMember
553ClientGitHash: string
622RunState: RunState
573BindToRenderStep(name: string, priority: int, function: Function): null
462GetCoreScriptVersion(): string
527GetRobloxClientChannel(): string
609GetRobloxGuiFocused(): bool
462GetRobloxVersion(): string
538IsClient(): bool
538IsEdit(): bool
538IsRunMode(): bool
462IsRunning(): bool
538IsServer(): bool
538IsStudio(): bool
573Pause(): null
573Reset(): null
573Run(): null
573Set3dRenderingEnabled(enable: bool): null
573SetRobloxGuiFocused(focus: bool): null
573Stop(): null
573UnbindFromRenderStep(name: string): null
573setThrottleFramerateEnabled(enable: bool): null
469Heartbeat(deltaTime: double)
548PostSimulation(deltaTimeSim: double)
548PreAnimation(deltaTimeSim: double)
548PreRender(deltaTimeRender: double)
548PreSimulation(deltaTimeSim: double)
469RenderStepped(deltaTime: double)
609RobloxGuiFocusedChanged(isRobloxGuiFocused: bool)
469Stepped(time: double, deltaTime: double)
inherited from Instance
553Archivable: bool
635Capabilities: SecurityCapabilities
553Name: string
553Parent: Instance
635Sandboxed: bool
616UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
486GetDescendants(): Array
486GetFullName(): string
641GetStyled(name: string): Variant
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
580IsPropertyModified(name: string): bool
573Remove(): null
576RemoveTag(tag: string): null
580ResetPropertyToDefault(name: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
648children(): Instances
553clone(): Instance
573destroy(): null
553findFirstChild(name: string, recursive: bool = false): Instance
648getChildren(): Instances
553isDescendantOf(ancestor: Instance): bool
573remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
553childAdded(child: Instance)
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Removed member index 1

HistoryMember
347RobloxOnlyIsEdit(): bool

Description

RunService contains methods and events for time management as well as for managing the context in which an experience or script is running. Methods like IsClient(), IsServer(), and IsStudio() can help you determine under what context code is running. These methods are useful for ModuleScripts that may be required by both client and server scripts. Furthermore, IsStudio() can be used to add special behaviors for in‑Studio testing.

RunService also houses events that allow your code to adhere to Roblox's frame‑by‑frame loop, such as PreRender, PreAnimation, PreSimulation, PostSimulation, and Heartbeat. Selecting the proper event to use for any case is important, so you should read Task Scheduler to make an informed decision.

Context Test Results

EnvironmentIsStudioIsClientIsServerIsEditIsRunningIsRunMode
Live Playerfalsetruefalse
Live Serverfalsefalsetrue
Edit Modetruetruetruetruefalsefalse
Collaborative Edittruetruefalsetruefalsefalse
Run Modetruetruetruefalsetruetrue
Play Mode (Client)truetruefalsefalsetruefalse
Play Mode (Server)truefalsetruefalsetruetrue
Team Test (Player)truetruefalsefalsetruefalse
Team Test (Server)falsefalsetruefalsetruefalse

History 103

Members 29

BindToRenderStep

Parameters (3)
namestring
priorityint
functionFunction
Returns (1)
null

The BindToRenderStep() function binds a custom function to be called at a specific time during the render step. There are three main arguments: name, priority, and what function to call.

As it is linked to the client's rendering process, BindToRenderStep() can only be called on the client.

Name

The name parameter is a label for the binding and can be used with RunService:UnbindFromRenderStep() if the binding is no longer needed.

1
2
3
4
5
6
7
8
local RunService = game:GetService("RunService")

local function functionToBind() end

-- Bind the function above to the binding named "tempBinding"
RunService:BindToRenderStep("tempBinding", 1, functionToBind)
-- Unbind the function bound to "tempBinding"
RunService:UnbindFromRenderStep("tempBinding")

Priority

The priority of the binding is an integer; it determines when during the render step to call the custom function. The lower this number, the sooner the custom function will be called. If two bindings have the same priority, the Roblox engine will randomly pick one to run first. The default Roblox control scripts run with these specific priorities:

  • Player Input: 100
  • Camera Controls: 200 For convenience; the RenderPriority enum can be used to determine the integer value to set a binding. For example, to make a binding right before the default camera update, simply subtract 1 from the camera priority level.

When using RenderPriority, remember to use .Value at the end of the desired enum. RunService:BindToRenderStep() will not work if just the enum is used on its own.

1
2
3
4
5
6
7
local RunService = game:GetService("RunService")

local function beforeCamera(delta)
	-- Code in here will run before the default Roblox camera script
end

RunService:BindToRenderStep("Before camera", Enum.RenderPriority.Camera.Value - 1, beforeCamera)

Custom Function and Delta Time

The last argument (function) is the custom function to call. This function will be passed one parameter called deltaTime which shows how much time passed between the beginning of the previous render step and the beginning of the current render step.

All rendering updates will wait until the code in the render step finishes. Make sure that any code called by BindToRenderStep() runs quickly and efficiently; if code takes too long, the experience visuals will be choppy.

History 3

ClientGitHash

TypeDefault
string
This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 3

Tags: [ReadOnly, NotReplicated]

GetCoreScriptVersion

Parameters (0)
No parameters.
Returns (1)
string

History 2

GetRobloxClientChannel

Parameters (0)
No parameters.
Returns (1)
string

History 1

GetRobloxGuiFocused

Parameters (0)
No parameters.
Returns (1)
bool

History 1

GetRobloxVersion

Parameters (0)
No parameters.
Returns (1)
string

History 4

Heartbeat

Parameters (1)
deltaTimedouble

The Heartbeat event fires every frame, after the physics simulation has completed. The deltaTime argument indicates the time that has elapsed since the previous frame.

This event is when most scripts run. It occurs at the end of each frame and it's also when any waiting scripts are executed, such as those scheduled with the task library. Heartbeat is commonly used for periodic tasks, such as updating core game systems like health regeneration.

Following this step, the engine sends property updates and events to the server or clients which are later received as part of the replication receive step.

History 7

IsClient

Parameters (0)
No parameters.
Returns (1)
bool

If the code that invoked this method is running in a client context (in a LocalScript, in a ModuleScript required by a LocalScript, or in a Script with RunContext set to RunContext.Client), this method will return true. In all other cases, this method will return false.

If this method returns true, the current environment can access client‑only features like RunService.PreRender or Players.LocalPlayer.

History 3

IsEdit

Parameters (0)
No parameters.
Returns (1)
bool

This method returns whether the current environment is in "edit" mode, for example in Studio when the experience is not running.

IsEdit() will return the inverse of IsRunning(), except when the simulation has been paused, in which case both methods will return false.

History 5

IsRunMode

Parameters (0)
No parameters.
Returns (1)
bool

This method returns whether the Run button has been pressed to run the simulation in Studio. It will continue to return true if the simulation has been paused using the Pause button; however, once it has been stopped using the Stop button, it will revert to returning false.

Note that Studio only enters "run" mode when the Run button is pressed, not the Play button. Also note that this method will return false if the simulation was started using RunService:Run() rather than the Run button.

History 3

IsRunning

Parameters (0)
No parameters.
Returns (1)
bool

Returns whether the experience is currently running, meaning the simulation has been run using the Run or Play buttons.

IsRunning() will always return the inverse of IsEdit() except when the simulation has been paused, in which case both methods will return false.

History 3

IsServer

Parameters (0)
No parameters.
Returns (1)
bool

This method returns whether the current environment is running on the server. If the code that invoked this method is running in a server context (in a Script with RunContext set to RunContext.Server or RunContext.Legacy, or in a ModuleScript required by a Script), this method will return true. In all other cases, this method will return false.

If this function returns true, then the current environment can access server‑only features like ServerStorage or ServerScriptService.

History 3

IsStudio

Parameters (0)
No parameters.
Returns (1)
bool

This method returns whether the current environment is running in Studio. It can be used to wrap code that should only execute when testing in Studio.

History 3

Pause

Parameters (0)
No parameters.
Returns (1)
null

This method pauses the experience's simulation if it is running, suspending physics and scripts. The simulation can be started using Run() or the Run button in Studio; when the simulation is paused, IsRunning() will return false.

History 5

PostSimulation

Parameters (1)
deltaTimeSimdouble

The PostSimulation event fires every frame, after the physics simulation has completed. The deltaTimeSim argument indicates the time that has elapsed since the previous frame.

This event is useful for making final adjustments to the outcome of the simulation. Following this phase, the engine triggers the Heartbeat event.

History 2

PreAnimation

Parameters (1)
deltaTimeSimdouble

The PreAnimation event fires every frame, prior to the physics simulation but after rendering. The deltaTimeSim argument indicates the time that has elapsed since the previous frame.

This event is useful for modifying animation objects, such as adjusting their speed or priority. Once the PreAnimation event is complete, the engine proceeds to run these animations, updating the joint transforms which will later be used to update objects during the physics simulation.

After animations are stepped, the engine triggers the PreSimulation event.

History 2

PreRender

Parameters (1)
deltaTimeRenderdouble

The PreRender event (equivalent to RenderStepped) fires every frame, prior to the frame being rendered. The deltaTimeRender argument indicates the time that has elapsed since the previous frame.

This event allows you to run code and update the world before it's drawn on a player's screen. This is useful for last‑minute adjustments such as changing object positions, updating animations, or preparing visual effects, but it should be used sparingly as the engine cannot start to render the frame until code running in this event has finished executing.

As PreRender is client-side, it can only be used in a LocalScript, in a ModuleScript required by a LocalScript, or in a Script with RunContext set to RunContext.Client.

Following the PreRender phase, the simulation phase begins with the PreAnimation event.

History 2

PreSimulation

Parameters (1)
deltaTimeSimdouble

The PreSimulation event (equivalent to Stepped) fires every frame, prior to the physics simulation. The deltaTimeSim argument indicates the time that has elapsed since the previous frame.

This event is useful for adjusting properties like velocity or forces just before they're applied as part of the simulation. The simulation then runs, potentially multiple times, as the physics solver runs at a higher frequency than other engine systems. Once this is complete, the PostSimulation event is fired.

History 2

RenderStepped

Parameters (1)
deltaTimedouble

The RenderStepped event (equivalent to PreRender) fires every frame, prior to the frame being rendered. The deltaTime argument indicates the time that has elapsed since the previous frame.

This event allows you to run code and update the world before it's drawn on a player's screen. This is useful for last‑minute adjustments such as changing object positions, updating animations, or preparing visual effects, but it should be used sparingly as the engine cannot start to render the frame until code running in this event has finished executing.

As RenderStepped is client-side, it can only be used in a LocalScript, in a ModuleScript required by a LocalScript, or in a Script with RunContext set to RunContext.Client.

Following the RenderStepped phase, the simulation phase begins with the PreAnimation event.

History 6

Reset

Parameters (0)
No parameters.
Returns (1)
null

The Reset function resets the current game to a waypoint set when Run was called. This method should only be used after Run was called.

This function is deprecated. It exists only for backward compatibility, and should not be used for new work.

History 6

  • 573 Change ReturnType of Reset from void to null
  • 462 Change ThreadSafety of Reset from to Unsafe
  • 151 Change Security of Reset from security1 to PluginSecurity
  • 150 Change Security of Reset from LocalUserSecurity to security1
  • 76 Change Tags of Reset from [] to [Deprecated]
  • 47 Add Reset
Tags: [Deprecated]

RobloxGuiFocusedChanged

Parameters (1)
isRobloxGuiFocusedbool

History 1

Run

Parameters (0)
No parameters.
Returns (1)
null

This method runs the experience's simulation (physics and scripts). When the simulation is running, IsRunning() will return true. However, IsRunMode() will only return true if the simulation was started using the Run button in Studio.

History 5

  • 573 Change ReturnType of Run from void to null
  • 462 Change ThreadSafety of Run from to Unsafe
  • 151 Change Security of Run from security1 to PluginSecurity
  • 150 Change Security of Run from LocalUserSecurity to security1
  • 47 Add Run

RunState

TypeDefault
RunState
This property is not replicated. Its interface does not cross the network boundary.

History 4

  • 622 Change WriteSecurity of RunState from RobloxScriptSecurity to PluginSecurity
  • 622 Change Tags of RunState from [Hidden, NotReplicated] to [NotReplicated]
  • 622 Change ReadSecurity of RunState from RobloxScriptSecurity to PluginSecurity
  • 615 Add RunState
Tags: [NotReplicated]

Set3dRenderingEnabled

Parameters (1)
enablebool
Returns (1)
null

History 3

SetRobloxGuiFocused

Parameters (1)
focusbool
Returns (1)
null

History 3

Stepped

Parameters (2)
timedouble
deltaTimedouble

The Stepped event (equivalent to PreSimulation) fires every frame, prior to the physics simulation. The deltaTime argument indicates the time that has elapsed since the previous frame.

This event is useful for adjusting properties like velocity or forces just before they're applied as part of the simulation. The simulation then runs, potentially multiple times, as the physics solver runs at a higher frequency than other engine systems. Once this is complete, the PostSimulation event is fired.

History 7

Stop

Parameters (0)
No parameters.
Returns (1)
null

This method stops the experience's simulation if it is running. When the simulation is stopped, IsRunning() will return false and IsEdit() will return true.

In contrast to the Stop button in Studio, calling this method will not restore the experience to the state it was in prior to the simulation being run. This means any changes made to the experience by the physics simulation and scripts will persist after the simulation has ended.

History 5

  • 573 Change ReturnType of Stop from void to null
  • 462 Change ThreadSafety of Stop from to Unsafe
  • 151 Change Security of Stop from security1 to PluginSecurity
  • 150 Change Security of Stop from LocalUserSecurity to security1
  • 76 Add Stop

UnbindFromRenderStep

Parameters (1)
namestring
Returns (1)
null

Given a name of a function sent to BindToRenderStep(), this method will unbind the function from being called during PreRender. This is used to unbind bound functions once they are no longer needed, or when they no longer need to fire every step.

If there is no bound function by the given name, this method takes no action and continues without raising an error.

History 3

setThrottleFramerateEnabled

Parameters (1)
enablebool
Returns (1)
null

History 3

Removed members 1

RobloxOnlyIsEdit

Parameters (0)
No parameters.
Returns (1)
bool

History 2

Settings