RunService

RunService : Instance

Overview

A RunService allows you to handle logic using frame-based loop events and identify whether the currently operating environment is a server, Studio, or client.

This ability to check the operating environment is particularly useful in ModuleScripts shared between the client and server, when they have to implement different behavior based on the environment.

Properties

ClientGitHash

string

Currently not supported.

Code Samples

Methods

IsClient

Returns whether the code that called the method is running in the client environment.

Returns true if it is called by a LocalScript or a ModuleScript loaded by a LocalScript.

Parameters

bool

Specifies whether it is running in the client environment.

Code Samples

local RunService = game:GetService("RunService")

local IsClient = RunService:IsClient()
print("IsClient : ", IsClient)

IsServer

Returns whether the code that called the method is running in the server environment.

Returns true if it is called by a server-side Script or a ModuleScript loaded by a Script.

Parameters

bool

Specifies whether it is running in the server environment.

Code Samples

local RunService = game:GetService("RunService")

local IsServer = RunService:IsServer()
print("IsServer : ", IsServer)

IsStudio

Returns whether the current client is running in the Studio environment.

This is useful for conditionally running a test code that should only run in Studio.

Parameters

bool

Specifies whether it is running in the Studio environment.

Code Samples

local RunService = game:GetService("RunService")

local IsStudio = RunService:IsStudio()
print("IsStudio : ", IsStudio)

Events

Heartbeat

After the physics simulation is completed, this event is called at the final step of every frame.

This is the typical execution point for scripts, where scripts scheduled via task.delay or task.spawn are also processed at this time.

This event is ideal for logic that needs to run periodically, such as health regeneration or timer updates.

Parameters

number deltaTime

The elapsed time in seconds between the previous frame and the current frame.

Can be used for calculations based on the time interval between frames.

Code Samples

local RunService = game:GetService("RunService")
local Timer = 0

local function UpdateEvent(deltaTime)
    Timer = Timer + deltaTime
    print(Timer)
end
RunService.Heartbeat:Connect(UpdateEvent)

Stepped

This event is called every frame before the physics simulation begins.

Parameters

number time

The elapsed time in seconds since RunService started.

number deltaTime

The elapsed time in seconds between the previous frame and the current frame.

Can be used for calculations based on the time interval between frames.

Code Samples

local RunService = game:GetService("RunService")

local function OnStepped(timeElapsed, deltaTime)
    print(timeElapsed)
end
RunService.Stepped:Connect(OnStepped)

RenderStepped

This event is called every frame before the frame is rendered on the screen.

Parameters

number deltaTime

The elapsed time in seconds between the previous frame and the current frame.

Can be used for calculations based on the time interval between frames.

Code Samples

local RunService = game:GetService("RunService")
local Timer = 0

local function OnRenderStepped(deltaTime)
    Timer = Timer + deltaTime
    print(Timer)
end
RunService.RenderStepped:Connect(OnRenderStepped)

Last updated