RunService
Service responsible for all runtime activity and progression of time.
Memory category | Instances |
---|
Member index 29
Removed member index 1
History | Member | |
---|---|---|
347 | RobloxOnlyIsEdit(): 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
Environment | IsStudio | IsClient | IsServer | IsEdit | IsRunning | IsRunMode |
---|---|---|---|---|---|---|
Live Player | false | true | false | |||
Live Server | false | false | true | |||
Edit Mode | true | true | true | true | false | false |
Collaborative Edit | true | true | false | true | false | false |
Run Mode | true | true | true | false | true | true |
Play Mode (Client) | true | true | false | false | true | false |
Play Mode (Server) | true | false | true | false | true | true |
Team Test (Player) | true | true | false | false | true | false |
Team Test (Server) | false | false | true | false | true | false |
History 103
- 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
- 609 Add RobloxGuiFocusedChanged
- 609 Add GetRobloxGuiFocused
- 573 Change ReturnType of setThrottleFramerateEnabled from void to null
- 573 Change ReturnType of UnbindFromRenderStep from void to null
- 573 Change ReturnType of Stop from void to null
- 573 Change ReturnType of SetRobloxGuiFocused from void to null
- 573 Change ReturnType of Set3dRenderingEnabled from void to null
- 573 Change ReturnType of Run from void to null
- 573 Change ReturnType of Reset from void to null
- 573 Change ReturnType of Pause from void to null
- 573 Change ReturnType of BindToRenderStep from void to null
- 553 Change Default of ClientGitHash from to
- 548 Change Parameters of PreSimulation from (deltaTime: double) to (deltaTimeSim: double)
- 548 Change Parameters of PreRender from (deltaTime: double) to (deltaTimeRender: double)
- 548 Change Parameters of PreAnimation from (deltaTime: double) to (deltaTimeSim: double)
- 548 Change Parameters of PostSimulation from (deltaTime: double) to (deltaTimeSim: double)
- 538 Change ThreadSafety of IsStudio from Unsafe to Safe
- 538 Change ThreadSafety of IsServer from Unsafe to Safe
- 538 Change ThreadSafety of IsRunMode from Unsafe to Safe
- 538 Change ThreadSafety of IsEdit from Unsafe to Safe
- 538 Change ThreadSafety of IsClient from Unsafe to Safe
- 527 Add GetRobloxClientChannel
- 486 Change ThreadSafety of ClientGitHash from ReadOnly to ReadSafe
- 483 Add ClientGitHash
- 469 Change Tags of Stepped from [Deprecated] to []
- 469 Change Tags of RenderStepped from [Deprecated] to []
- 469 Change Tags of Heartbeat from [Deprecated] to []
- 466 Change Tags of Stepped from [] to [Deprecated]
- 466 Change Parameters of Stepped from (time: double, step: double) to (time: double, deltaTime: double)
- 466 Change Parameters of RenderStepped from (step: double) to (deltaTime: double)
- 466 Change Tags of RenderStepped from [] to [Deprecated]
- 466 Add PreSimulation
- 466 Add PreRender
- 466 Add PreAnimation
- 466 Add PostSimulation
- 466 Change Tags of Heartbeat from [] to [Deprecated]
- 466 Change Parameters of Heartbeat from (step: double) to (deltaTime: double)
- 462 Change ThreadSafety of Stepped from to Unsafe
- 462 Change ThreadSafety of RenderStepped from to Unsafe
- 462 Change ThreadSafety of Heartbeat from to Unsafe
- 462 Change ThreadSafety of setThrottleFramerateEnabled from to Unsafe
- 462 Change ThreadSafety of UnbindFromRenderStep from to Unsafe
- 462 Change ThreadSafety of Stop from to Unsafe
- 462 Change ThreadSafety of SetRobloxGuiFocused from to Unsafe
- 462 Change ThreadSafety of Set3dRenderingEnabled from to Unsafe
- 462 Change ThreadSafety of Run from to Unsafe
- 462 Change ThreadSafety of Reset from to Unsafe
- 462 Change ThreadSafety of Pause from to Unsafe
- 462 Change ThreadSafety of IsStudio from to Unsafe
- 462 Change ThreadSafety of IsServer from to Unsafe
- 462 Change ThreadSafety of IsRunning from to Unsafe
- 462 Change ThreadSafety of IsRunMode from to Unsafe
- 462 Change ThreadSafety of IsEdit from to Unsafe
- 462 Change ThreadSafety of IsClient from to Unsafe
- 462 Change ThreadSafety of GetRobloxVersion from to Unsafe
- 462 Change ThreadSafety of GetCoreScriptVersion from to Unsafe
- 462 Change ThreadSafety of BindToRenderStep from to Unsafe
- 441 Add GetCoreScriptVersion
- 347 Remove RobloxOnlyIsEdit
- 345 Add SetRobloxGuiFocused
- 334 Add IsEdit
- 328 Add RobloxOnlyIsEdit
- 328 Remove IsEdit
- 327 Add IsEdit
- 317 Add Set3dRenderingEnabled
- 307 Add setThrottleFramerateEnabled
- 302 Add GetRobloxVersion
- 301 Remove GetRobloxVersion
- 302 Add GetRobloxVersion
- 297 Change Security of IsRunning from RobloxScriptSecurity to None
- 213 Add IsStudio
- 213 Add IsServer
- 213 Add IsRunMode
- 213 Add IsClient
- 208 Change Parameters of RenderStepped from () to (step: double)
- 187 Add UnbindFromRenderStep
- 187 Add BindToRenderStep
- 184 Add IsRunning
- 151 Change Security of Stop from security1 to PluginSecurity
- 151 Change Security of Run from security1 to PluginSecurity
- 151 Change Security of Reset from security1 to PluginSecurity
- 151 Change Security of Pause from security1 to PluginSecurity
- 150 Change Security of Stop from LocalUserSecurity to security1
- 150 Change Security of Run from LocalUserSecurity to security1
- 150 Change Security of Reset from LocalUserSecurity to security1
- 150 Change Security of Pause from LocalUserSecurity to security1
- 132 Change Tags of Stepped from [Deprecated] to []
- 132 Add RenderStepped
- 132 Change Tags of Heartbeat from [Deprecated] to []
- 76 Add Stop
- 76 Change Tags of Reset from [] to [Deprecated]
- 61 Change Tags of Stepped from [] to [Deprecated]
- 61 Change Tags of Heartbeat from [] to [Deprecated]
- 47 Add Stepped
- 47 Add Heartbeat
- 47 Add Run
- 47 Add Reset
- 47 Add Pause
- 47 Add RunService
Members 29
BindToRenderStep
Parameters (3) | ||
---|---|---|
name | string | |
priority | int | |
function | Function | |
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 |
|
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 subtract1
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 |
|
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.
Thread safety | Unsafe |
---|
History 3
- 573 Change ReturnType of BindToRenderStep from void to null
- 462 Change ThreadSafety of BindToRenderStep from to Unsafe
- 187 Add BindToRenderStep
ClientGitHash
Type | Default | |
---|---|---|
string |
Security | RobloxScriptSecurity |
---|---|
Thread safety | ReadSafe |
Category | Data |
Loaded/Saved | false |
History 3
- 553 Change Default of ClientGitHash from to
- 486 Change ThreadSafety of ClientGitHash from ReadOnly to ReadSafe
- 483 Add ClientGitHash
GetCoreScriptVersion
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
string |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 462 Change ThreadSafety of GetCoreScriptVersion from to Unsafe
- 441 Add GetCoreScriptVersion
GetRobloxClientChannel
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
string |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 1
GetRobloxGuiFocused
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 1
GetRobloxVersion
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
string |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 4
- 462 Change ThreadSafety of GetRobloxVersion from to Unsafe
- 302 Add GetRobloxVersion
- 301 Remove GetRobloxVersion
- 302 Add GetRobloxVersion
Heartbeat
Parameters (1) | |
---|---|
deltaTime | double |
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.
Thread safety | Unsafe |
---|
History 7
- 469 Change Tags of Heartbeat from [Deprecated] to []
- 466 Change Tags of Heartbeat from [] to [Deprecated]
- 466 Change Parameters of Heartbeat from (step: double) to (deltaTime: double)
- 462 Change ThreadSafety of Heartbeat from to Unsafe
- 132 Change Tags of Heartbeat from [Deprecated] to []
- 61 Change Tags of Heartbeat from [] to [Deprecated]
- 47 Add Heartbeat
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.
Thread safety | Safe |
---|
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
.
Security | PluginSecurity |
---|---|
Thread safety | Safe |
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.
Thread safety | Safe |
---|
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
.
Thread safety | Unsafe |
---|
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.
Thread safety | Safe |
---|
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.
Thread safety | Safe |
---|
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
.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
PostSimulation
Parameters (1) | |
---|---|
deltaTimeSim | double |
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.
Thread safety | Unsafe |
---|
History 2
- 548 Change Parameters of PostSimulation from (deltaTime: double) to (deltaTimeSim: double)
- 466 Add PostSimulation
PreAnimation
Parameters (1) | |
---|---|
deltaTimeSim | double |
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.
Thread safety | Unsafe |
---|
History 2
- 548 Change Parameters of PreAnimation from (deltaTime: double) to (deltaTimeSim: double)
- 466 Add PreAnimation
PreRender
Parameters (1) | |
---|---|
deltaTimeRender | double |
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.
Thread safety | Unsafe |
---|
PreSimulation
Parameters (1) | |
---|---|
deltaTimeSim | double |
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.
Thread safety | Unsafe |
---|
History 2
- 548 Change Parameters of PreSimulation from (deltaTime: double) to (deltaTimeSim: double)
- 466 Add PreSimulation
RenderStepped
Parameters (1) | |
---|---|
deltaTime | double |
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.
Thread safety | Unsafe |
---|
History 6
- 469 Change Tags of RenderStepped from [Deprecated] to []
- 466 Change Parameters of RenderStepped from (step: double) to (deltaTime: double)
- 466 Change Tags of RenderStepped from [] to [Deprecated]
- 462 Change ThreadSafety of RenderStepped from to Unsafe
- 208 Change Parameters of RenderStepped from () to (step: double)
- 132 Add RenderStepped
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.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
RobloxGuiFocusedChanged
Parameters (1) | |
---|---|
isRobloxGuiFocused | bool |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
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.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
RunState
Type | Default | |
---|---|---|
RunState |
Security | PluginSecurity |
---|---|
Thread safety | ReadSafe |
Category | Data |
Loaded/Saved | false |
Set3dRenderingEnabled
Parameters (1) | ||
---|---|---|
enable | bool | |
Returns (1) | ||
null |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 3
- 573 Change ReturnType of Set3dRenderingEnabled from void to null
- 462 Change ThreadSafety of Set3dRenderingEnabled from to Unsafe
- 317 Add Set3dRenderingEnabled
SetRobloxGuiFocused
Parameters (1) | ||
---|---|---|
focus | bool | |
Returns (1) | ||
null |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 3
- 573 Change ReturnType of SetRobloxGuiFocused from void to null
- 462 Change ThreadSafety of SetRobloxGuiFocused from to Unsafe
- 345 Add SetRobloxGuiFocused
Stepped
Parameters (2) | |
---|---|
time | double |
deltaTime | double |
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.
Thread safety | Unsafe |
---|
History 7
- 469 Change Tags of Stepped from [Deprecated] to []
- 466 Change Tags of Stepped from [] to [Deprecated]
- 466 Change Parameters of Stepped from (time: double, step: double) to (time: double, deltaTime: double)
- 462 Change ThreadSafety of Stepped from to Unsafe
- 132 Change Tags of Stepped from [Deprecated] to []
- 61 Change Tags of Stepped from [] to [Deprecated]
- 47 Add Stepped
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.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
UnbindFromRenderStep
Parameters (1) | ||
---|---|---|
name | string | |
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.
Thread safety | Unsafe |
---|
History 3
- 573 Change ReturnType of UnbindFromRenderStep from void to null
- 462 Change ThreadSafety of UnbindFromRenderStep from to Unsafe
- 187 Add UnbindFromRenderStep
setThrottleFramerateEnabled
Parameters (1) | ||
---|---|---|
enable | bool | |
Returns (1) | ||
null |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 3
- 573 Change ReturnType of setThrottleFramerateEnabled from void to null
- 462 Change ThreadSafety of setThrottleFramerateEnabled from to Unsafe
- 307 Add setThrottleFramerateEnabled
Removed members 1
RobloxOnlyIsEdit
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
Security | RobloxScriptSecurity |
---|
History 2
- 347 Remove RobloxOnlyIsEdit
- 328 Add RobloxOnlyIsEdit