RunService
Game service responsible for all run-time 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 a game or script is running. Methods like IsClient, IsServer, 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 PreAnimation, PreSimulation, Heartbeat and PreRender. Selecting the proper event to use for any case is important, so you should read Task Scheduler to make an informed decision.
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 for
BindToRenderStep: 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, and 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 |
|
Custom Function and Delta Time
The last argument of BindToRenderStep is the custom function
to call.
This function will be passed one parameter called deltaTime.
DeltaTime 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 in BindToRenderStep takes too long, then the game 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 step argument indicates the time that has elapsed since the previous frame.
As Heartbeat fires every frame, it runs on a variable frequency. This means the rate will vary depending on the performance of the machine. If the game is running at 40 FPS, then Heartbeat will fire 40 times per second and the step argument will be roughly 1/40th of a second.
The step argument can be used to account for the variable frequency of this event, for example:
1 2 3 4 5 6 7 |
|
There is no guarantee that functions connected to this event will fire at the exact same time, or in any specific order. For an alternative where the priority can be specified, see RunService:BindToRenderStep().
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 |
This function returns whether the current environment is running on the client.
If the code that invoked this method is running in a client context (in a LocalScript or a ModuleScript required by a LocalScript) then this method will return true. In all other cases, this function will return false.
If this function returns true, then the current environment can access client-only features like RunService.PreRender or Players.LocalPlayer.
RunService test function 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 |
Edit Mode (Team Create) | 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 |
Legacy Play Mode † | true | true | true | false | true | false |
See also:
Thread safety | Safe |
---|
IsEdit
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
This function returns whether the current environment is in 'Edit' mode. For example, Roblox Studio is in 'Edit Mode' when the game is not running.
IsEdit will return the inverse of RunService:IsRunning() with one exception, if the simulation has been 'paused' then both IsEdit and RunService:IsRunning() will return false.
See also:
Security | PluginSecurity |
---|---|
Thread safety | Safe |
IsRunMode
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
This function returns whether the 'Run' button has been pressed to run the simulation in Roblox Studio.
If the user has pressed 'Run', then this function will return true. This function 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.
Roblox Studio only enters run mode when the 'Run' button is pressed, not the 'Play' button. This function will also return false if the simulation was started using RunService:Run() rather than the 'Run' button.
RunService test function results
See also:
Thread safety | Safe |
---|
IsRunning
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
Returns whether the game is currently running
The game is considered running when it is not in edit mode in Roblox Studio. This means, if the simulation has been run using the 'Run' or 'Play' buttons the game is running.
IsRunning will always return the inverse of RunService:IsEdit() with one exception, if the simulation has been 'paused' then both RunService:IsEdit() and IsRunning will return false.
RunService test function results
See also:
Thread safety | Unsafe |
---|
IsServer
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
This function 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 or a ModuleScript required by a Script) then this method will return true. In all other cases, this function will return false.
If this function returns true, then the current environment can access server-only features like ServerStorage or ServerScriptService.
See also:
Thread safety | Safe |
---|
IsStudio
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
bool |
This function returns whether the current environment is running in Roblox Studio.
This function will only return true when using Roblox Studio and can be used to add code to test your game within Studio.
See also:
Thread safety | Safe |
---|
Pause
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
null |
This function pauses the games' simulation if it is running, suspending physics and scripts.
The simulation can be started using RunService:Run() or the 'Run' button in Roblox Studio. When the simulation is paused, RunService:IsRunning() will return false.
Pausing the simulation can be used to assist with debugging in Roblox Studio, it cannot be used in real game sessions.
See also:
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
PostSimulation
Parameters (1) | |
---|---|
deltaTimeSim | double |
Thread safety | Unsafe |
---|
History 2
- 548 Change Parameters of PostSimulation from (deltaTime: double) to (deltaTimeSim: double)
- 466 Add PostSimulation
PreAnimation
Parameters (1) | |
---|---|
deltaTimeSim | double |
Thread safety | Unsafe |
---|
History 2
- 548 Change Parameters of PreAnimation from (deltaTime: double) to (deltaTimeSim: double)
- 466 Add PreAnimation
PreRender
Parameters (1) | |
---|---|
deltaTimeRender | double |
Thread safety | Unsafe |
---|
PreSimulation
Parameters (1) | |
---|---|
deltaTimeSim | double |
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 fires every frame, prior to the frame being rendered. The step argument indicates the time that has elapsed since the previous frame.
RenderStepped does not run in parallel to Roblox's rendering tasks and code connected to RenderStepped must be executed prior to the frame being rendered. This can lead to significant performance issues if RenderStepped is used inappropriately. To avoid this, only use RenderStepped for code that works with the camera or character. Otherwise, RunService.Heartbeat should be used.
As RenderStepped fires every frame, it runs on a variable frequency. This means the rate will vary depending on the performance of the machine. If the game is running at 40 FPS, then RenderStepped will fire 40 times per second and the step argument will be roughly 1/40th of a second.
The step argument can be used to account for the variable frequency of this event, for example:
1 2 3 4 5 6 7 |
|
There is no guarantee that functions connected to this event will fire at the exact same time, or in any specific order. For an alternative where the priority can be specified, see RunService:BindToRenderStep().
As RenderStepped is client-side only, it can be used in a LocalScript or a ModuleScript required by a LocalScript.
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 function runs the game's simulation, running physics and scripts.
When the simulation is running, RunService:IsRunning() will return true. However, RunService:IsRunMode() will only return true if the simulation was started using the 'Run' button in Roblox Studio. This means when this function is used to start the simulation, IsRunMode will return false even though the simulation is running.
The simulation can be paused using RunService:Pause() or the 'Pause' button in Roblox Studio. It can also be ended using RunService:Stop().
Running the simulation can be used to assist with debugging in Roblox Studio. Currently it is not possible to restore the game to the state it was in prior to running the simulation if the simulation was started using this function. If this is a problem, instead use the 'Run' button in Roblox Studio.
See also:
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 fires every frame prior to the physics simulation. The step argument indicates the time that has elapsed since the previous frame.
As Stepped fires every frame, it runs on a variable frequency. This means the rate will vary depending on the performance of the machine. If the game is running at 40 FPS, then Stepped will fire 40 times per second and the step argument will be roughly 1/40th of a second.
The step argument can be used to account for the variable frequency of this event, for example:
1 2 3 4 5 6 7 |
|
There is no guarantee that functions connected to this event will fire at the exact same time, or in any specific order. For an alternative where the priority can be specified, see RunService:BindToRenderStep().
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 function ends the game's simulation if it is running.
The simulation can be started using RunService:Run() or the 'Run' button in Roblox Studio. When the simulation is stopped, RunService:IsRunning() will return false and RunService:IsEdit() will return true.
In contrast to the 'Stop' button in Roblox Studio, calling this function will not restore the game to the state it was in prior to the simulation being run. This means any changes made to the game by the physics simulation and scripts will persist after the simulation has ended.
See also:
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