Skip to Content
Kinemium
Services

RunService

Query how the game is running and hook code into render and simulation steps.

RunService tells you which kind of runtime your script is in, editor, server, client, or one of the combined modes, and lets you run code at specific points in the frame.

Getting started

local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function(deltaTime)
    print("Frame took", deltaTime, "seconds")
end)

Heartbeat fires once per frame after simulation. The delta time is in seconds and can vary from frame to frame, so multiply movement by it rather than assuming a fixed step.

Checking the runtime mode

MethodReturns true when
IsRunning()The game is running rather than open in the editor.
IsEdit()The current runtime is the editor.
IsStudio()The game is open in the editor or running as a playtest.
IsServer()Running as a server, standalone, or singleplayer.
IsClient()Running as a client, standalone, or singleplayer.
IsStandalone()Running as a standalone game.
IsSingleplayer()Running as singleplayer.
local RunService = game:GetService("RunService")

if RunService:IsServer() then
    print("Server-side logic")
elseif RunService:IsClient() then
    print("Client-side logic")
end

Standalone and singleplayer count as both server and client, because one runtime is doing both jobs. That means an IsServer() check doesn't guarantee other clients exist.

IsRunningAsync() currently always returns false. It isn't a way to detect an asynchronous runtime.

Step signals

SignalCallback argumentsWhen it fires
RenderSteppeddeltaTime: numberOnce per render step, after bound render callbacks run.
SteppedelapsedTime: number, deltaTime: numberOn each simulation step.
PostSimulationdeltaTime: numberAfter simulation finishes for the frame.
HeartbeatdeltaTime: numberOnce per frame, after simulation.
local RunService = game:GetService("RunService")

RunService.Stepped:Connect(function(elapsedTime, deltaTime)
    -- elapsedTime is total simulation time, deltaTime is this step.
    print(elapsedTime, deltaTime)
end)

elapsedTime is accumulated simulation time, not wall-clock time. It only advances while the game is stepping.

These signals come from the engine's Signal object, not a different event type, so Connect() and Once() behave the same way as on other engine events. If signal creation fails, accessing the property can return nil, so guard long-lived connections if you can't be sure the runtime is fully initialized.

Binding to the render step

BindToRenderStep() runs a named callback during rendering, which is where you want camera and UI work that must follow the rendered frame.

RunService:BindToRenderStep(name: string, callback: function): ()
RunService:BindToRenderStep(name: string, priority: number, callback: function): ()

The callback receives deltaTime. Lower priority numbers run first, and the overload without a priority uses 0.

local RunService = game:GetService("RunService")

local function updateCamera(deltaTime)
    -- Move the camera here.
end

RunService:BindToRenderStep("CameraUpdate", 200, updateCamera)

-- Later, or on teardown:
RunService:UnbindFromRenderStep("CameraUpdate")

Binding a name that's already in use replaces that binding's callback and priority instead of adding a second one, so you can rebind safely. UnbindFromRenderStep(name) does nothing if no binding has that name. The callback must be a function; anything else raises an error.

Bound callbacks and RenderStepped listeners run in the same render step, the named bindings first, then the signal, so a callback bound at a low priority runs before RenderStepped handlers regardless of connection order.

Notes

  • Work bound to the render step runs on the rendering path. Keep it short, and prefer Heartbeat or PostSimulation for game logic that doesn't need to match the frame.
  • IsServer() and IsClient() describe the runtime, not permissions. A client can still call a server-authoritative API locally; the server decides what's replicated.
  • The reflection metadata for this class only lists PostSimulation, but all four step signals and the state methods above are callable.

See also

  • Players, player and character events.
  • TweenService, time-based animation driven by the same frame loop.

On this page