PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

RenderStepped

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 Workspace/CurrentCamera|camera or Player/Character|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:

local RunService = game:GetService("RunService")

local RATE_PER_SECOND = 2

RunService.RenderStepped:Connect(function(step)
	local increment = RATE_PER_SECOND * step
end)

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.

Parameters

Name Type Default Description

The time (in seconds) that has elapsed since the previous frame


Code Samples


Spin GuiObject

This code sample rotates a parent GuiObject (such as a Frame) using a given rotation speed and the RunService/RenderStepped event.

local RunService = game:GetService("RunService")

local guiObject = script.Parent

local degreesPerSecond = 180

local function onRenderStep(deltaTime)
	local deltaRotation = deltaTime * degreesPerSecond
	guiObject.Rotation = guiObject.Rotation + deltaRotation 
end
RunService.RenderStepped:Connect(onRenderStep)