Skip to content

Service · inherits Instance

RunService

Official docs ↗

Service responsible for all runtime activity and progression of time.

About RunService

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 the engine'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

Properties 1

  • RunState: RunStateNotReplicatedThe current run state of the game's simulation.

    An RunState value that reflects whether the game's simulation is stopped, running, or paused. Reading reports the current state; setting it transitions the simulation, equivalent to RunService.Run, RunService.Pause, and RunService.Stop for the corresponding states. Defaults to RunState.Stopped. Setting this property requires Plugin security.

    The state reported here backs the context methods on RunService: it is Running when IsRunning() returns true, and Stopped when IsEdit() returns true.

Methods 16

  • BindToAnimation(function: Function, frequency: StepFrequency = Hz30, priority: int = 2000) → RBXScriptConnectionBinds a custom function to be called at a fixed frequency before Animators update when fixed simulation is enabled, or immediately before BindToSimulation callbacks otherwise.

    BindToAnimation() binds a custom function to be called at a fixed frequency which is independent of the frame rate. When Workspace.UseFixedSimulation is enabled, these functions are invoked before Animators update, making this the fixed-frequency counterpart to PreAnimation. When fixed simulation is disabled, they instead run immediately before BindToSimulation() callbacks, so no pre-animation ordering should be assumed. In the server authority model, bound functions will also get called when the client needs to resimulate.

    Like BindToSimulation(), the bound function is meant for physics controllers and prediction, so an error will trigger if you read or write from unsynchronized properties or call an unsynchronized method. This error is meant to help guide you in writing a pure, synchronized simulation.

    To synchronize inaccessible properties, you should store the relevant data in attributes and update the relevant property in PostSimulation or RenderStepped by reading from attributes. This will leverage attribute synchronization to keep the property fully synchronized through the rollback mechanism.

  • BindToRenderStep(name: string, priority: int, function: Function) → ()Given a string name of a function and a priority, this method binds the function to RunService.PreRender.

    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.

    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 engine will randomly pick one to run first. The default 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.

    local RunService = game:GetService("RunService")
    
    local function beforeCamera(delta)
        -- Code in here will run before the default 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.

  • BindToSimulation(function: Function, frequency: StepFrequency = Hz30, priority: int = 2000) → RBXScriptConnectionBinds a custom function to be called at a fixed frequency which is independent of the frame rate.

    BindToSimulation() binds a custom function to be called at a fixed frequency which is independent of the frame rate. In the server authority model, bound functions will also get called when the client needs to resimulate. This method is only available when Workspace.UseFixedSimulation is enabled.

    Note that since the bound function is meant for physics controllers and prediction, an error will trigger if you read or write from unsynchronized properties or call an unsynchronized method. This error is meant to help guide you in writing a pure, synchronized simulation.

    To synchronize inaccessible properties, you should store the relevant data in attributes and update the relevant property in PostSimulation or RenderStepped by reading from attributes. This will leverage attribute synchronization to keep the property fully synchronized through the rollback mechanism.

  • GetPredictionStatus(context: Instance) → PredictionStatusChecks the PredictionStatus of a specific context instance, useful for debugging scripts affecting multiple instances where some might be predicted and others might not.

    Clients can use this method to check the PredictionStatus of a specific context instance, useful for debugging scripts affecting multiple instances (vehicle controllers, custom physics, etc.) where some might be predicted and others might not. This method is also useful for debugging and observing the effects of PredictionMode.Automatic prediction mode.

  • IsClient() → booleanReturns 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, 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.

  • IsEdit() → booleanReturns whether the current environment is in Edit mode.

    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.

  • IsResimulating() → booleanReturns whether the client is currently in a resimulation step after a misprediction in the server authority model.

    Returns true if the engine is currently replaying simulation steps after detecting a misprediction in the server authority model; returns false otherwise. When the server's authoritative state diverges from the client's predicted state, the client rolls back and rapidly resimulates all affected steps within a single frame. During that resimulation pass, BindToSimulation() callbacks and property-changed signals fire again for each replayed step, which can cause unwanted side effects such as duplicate sound playback or redundant network requests.

  • IsRunMode() → booleanReturns whether a Run playtest has been initiated in Studio.

    This method returns whether a Run playtest has been initiated 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 a Run playtest (without the user's player character) is initiated. Also note that this method will return false if the simulation was started using RunService.Run.

  • IsRunning() → booleanReturns whether the experience is currently running.

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

  • IsServer() → booleanReturns whether the current environment is running on the server.

    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.

  • IsStudio() → booleanReturns whether the current environment is running in Studio.

    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.

  • Pause() → ()PluginPauses the experience's simulation if it is running, suspending physics and scripts.

    This method pauses the experience's simulation if it is running, suspending physics and scripts. When the simulation is paused, IsRunning() will return false.

  • Run() → ()PluginRuns the game's simulation, running physics and scripts.

    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.

  • SetPredictionMode(context: Instance, mode: PredictionMode) → ()Sets the prediction mode for an Instance to an PredictionMode value.

    Sets the prediction mode for an Instance (context) to an PredictionMode value. Mismatches between the physics properties or attributes for predicted instances will cause a rollback and resimulation on the client. Can only be called on the client.

  • Stop() → ()PluginStops the experience's simulation if it is running.

    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.

  • UnbindFromRenderStep(name: string) → ()Unbinds a function that was bound to the render loop using RunService.BindToRenderStep.

    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.

Events 9

  • HeartbeatRunService.Heartbeat:Connect(function(deltaTime))Fires every frame, after the physics simulation has completed.

    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.

  • MispredictionRunService.Misprediction:Connect(function(time, instances, stats))In the server authority model, fires during prediction when the engine detects that the client has diverged from the server's authoritative state. Intended for plugin-based debugging.

    With server authority enabled, the Misprediction event fires when a received server state differs from the predicted state.

    Use this event to build debugging tools that inspect misprediction data programmatically. For example, a plugin could listen for this event and track which instances are frequently mispredicting, what properties are diverging, and by how much.

    Instances Array

    Each entry in the instances array is a table with the following structure:

    Stats Dictionary

    The stats dictionary contains the following fields:

    Code Sample
  • PostSimulationRunService.PostSimulation:Connect(function(deltaTimeSim))Fires every frame, after the physics simulation has completed.

    The PostSimulation event fires every frame, after the physics simulation has completed. The deltaTimeSim argument indicates the time that the current frame has stepped the physics simulation, not accounting for physics throttling. This may deviate from the actual time between frames in Studio edit mode or when framerate is very low.

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

  • PreAnimationRunService.PreAnimation:Connect(function(deltaTimeSim))Fires every frame, prior to the physics simulation but after rendering.

    The PreAnimation event fires every frame, prior to the physics simulation but after rendering. The deltaTimeSim argument indicates the time that the current frame has stepped animations.

    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.

  • PreRenderRunService.PreRender:Connect(function(deltaTimeRender))Fires every frame, prior to the frame being rendered.

    The PreRender event (replacement for 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.

  • PreSimulationRunService.PreSimulation:Connect(function(deltaTimeSim))Fires every frame, prior to the physics simulation.

    The PreSimulation event (replacement for Stepped) fires every frame, prior to the physics simulation. The deltaTimeSim argument indicates the time that the current frame will step the physics simulation, not accounting for physics throttling. This may deviate from the actual time between frames in Studio edit mode or when framerate is very low.

    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.

  • RenderSteppedRunService.RenderStepped:Connect(function(deltaTime))Fires every frame, prior to the frame being rendered.

    Fires every frame, prior to the frame being rendered.

    Migration Note

    This event has been superseded by PreRender which should be used for new work.

  • RollbackRunService.Rollback:Connect(function(time))In the server authority model, this fires after rolling back the predicted state due to a misprediction, but before resimulation begins.

    When server authority is enabled, the Rollback event fires after the engine detects a misprediction and rolls back all eligible state (properties, attributes, and related physics and animation state), but before the engine resimulates the rolled-back steps.

    Use this event to update state in your place that wouldn't otherwise be rolled back after a misprediction. For example, if you maintain gameplay state that can't be stored in a property or attribute with simulation access, you can listen for this event, compare the rolled-back-to step against your farthest-reached step, and rewind your custom state accordingly.

  • SteppedRunService.Stepped:Connect(function(time, deltaTime))Fires every frame, prior to the physics simulation.

    Fires every frame, prior to the physics simulation.

    Migration Note

    This event has been superseded by PreSimulation which should be used for new work.

RunService also has every member of Instance. Deprecated and Roblox-only members are hidden.

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.