RunService

Show Deprecated
Not Creatable
Service
Not Replicated

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

Summary

Properties

Methods

  • BindToRenderStep(name : string,priority : number,function : function):()

    Given a string name of a function and a priority, this method binds the function to RunService.PreRender.

  • Write Parallel

    Returns whether the current environment is running on the client.

  • Plugin Security
    Write Parallel

    Returns whether the current environment is in Edit mode.

  • Write Parallel

    Returns whether the Run button has been pressed to run the simulation in Studio.

  • Returns whether the experience is currently running.

  • Write Parallel

    Returns whether the current environment is running on the server.

  • Write Parallel

    Returns whether the current environment is running in Studio.

  • Pause():()
    Plugin Security

    Pauses the experience's simulation if it is running, suspending physics and scripts.

  • Run():()
    Plugin Security

    Runs the game's simulation, running physics and scripts.

  • Stop():()
    Plugin Security

    Stops the experience's simulation if it is running.

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

Events

Properties

ClientGitHash

Read Only
Not Replicated
Roblox Script Security
Read Parallel
Not Replicated
Plugin Security
Read Parallel

Methods

BindToRenderStep

()

Parameters

name: string
priority: number
function: function

Returns

()

Code Samples

Frame Moving in Circle

local RunService = game:GetService("RunService")
-- How fast the frame ought to move
local SPEED = 2
local frame = script.Parent
frame.AnchorPoint = Vector2.new(0.5, 0.5)
-- A simple parametric equation of a circle
-- centered at (0.5, 0.5) with radius (0.5)
local function circle(t)
return 0.5 + math.cos(t) * 0.5, 0.5 + math.sin(t) * 0.5
end
-- Keep track of the current time
local currentTime = 0
local function onRenderStep(deltaTime)
-- Update the current time
currentTime = currentTime + deltaTime * SPEED
-- ...and the frame's position
local x, y = circle(currentTime)
frame.Position = UDim2.new(x, 0, y, 0)
end
-- This is just a visual effect, so use the "Last" priority
RunService:BindToRenderStep("FrameCircle", Enum.RenderPriority.Last.Value, onRenderStep)
--RunService.RenderStepped:Connect(onRenderStep) -- Also works, but not recommended
RunService Custom Function

local RunService = game:GetService("RunService")
local function checkDelta(deltaTime)
print("Time since last render step:", deltaTime)
end
RunService:BindToRenderStep("Check delta", Enum.RenderPriority.First.Value, checkDelta)
Bind and Unbind a Function

local RunService = game:GetService("RunService")
-- Step 1: Declare the function and a name
local NAME = "Print Hello"
local function printHello()
print("Hello")
end
-- Step 2: Bind the function
RunService:BindToRenderStep(NAME, Enum.RenderPriority.First.Value, printHello)
-- Step 3: Unbind the function
RunService:UnbindFromRenderStep(NAME)

IsClient

Write Parallel

Returns

IsEdit

Plugin Security
Write Parallel

Returns

IsRunMode

Write Parallel

Returns

IsRunning


Returns

IsServer

Write Parallel

Returns

IsStudio

Write Parallel

Returns

Pause

()
Plugin Security

Returns

()

Run

()
Plugin Security

Returns

()

Stop

()
Plugin Security

Returns

()

UnbindFromRenderStep

()

Parameters

name: string

Returns

()

Events

Heartbeat

Parameters

deltaTime: number

PostSimulation

Parameters

deltaTimeSim: number

PreAnimation

Parameters

deltaTimeSim: number

PreRender

Parameters

deltaTimeRender: number

PreSimulation

Parameters

deltaTimeSim: number

RenderStepped

Parameters

deltaTime: number

Stepped

Parameters

time: number
deltaTime: number