What does RenderStepped:Wait() do

isn’t it the same as the normal wait() function

1 Like

The wait() is longer than RenderStepped:Wait(), but task.wait() is equal (I believe) to RenderStepped:Wait()

1 Like

what do you mean ‘longer’, can you explain me it im kinda stupid

1 Like

RenderStepped is a client event that resumes every render cycle. If you need more fine control over priority, use BindToRenderStep. Passes time elapsed since last resumption when fired.

Here is usage example:

local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function(delta)
    print(delta)
end)
1 Like

if getting into main topic, RunService.RenderStepped:Wait() simply yields code until next render cycle.

2 Likes
  1. wait() can only wait for ~0.029 seconds at minimum (roughly how long a frame is at 30 FPS, source), it is recommended you use task.wait().

  2. RenderStepped:Wait() waits until after the next frame is rendered on the player’s screen.

1 Like

Just correcting both of you there.
wait() is a deprecated function that yields code ans resumes it using legacy methods with throttling after some time elapsed (additionally max resumption frequency is 30 Hz), where as task.wait() relies on RunService.Heartbeat event to resume code execution after time elapsed without throttling. RunService.Heartbeat runs after physics calculation, check out Task Scheduler documentation for more information

1 Like

Since RenderStepped is a RBXScriptSignal (event), it contains a few methods:

  • :Connect() - You better know about this one
  • :Wait() - Yields until the event is fired, returns the passed values
  • :Once() - Connects, but disconnects once fired

Therefore simply, it will yield the code until it fires, which will take one frame to do.

3 Likes

The Whole prupose of :Wait() in a Connection is Yield code until the Event is fired, which for the case of RenderStepped it would only yield for about 1/40th of a Second due to it firing Prior to (Before) Rendering.

With the :Wait() function, you can simply tell the code to yield something until something is done (which means that something fired) and then it would resume, Like this for example, here we have a Tween that was Created using TweenService, We would then Play it to do a Specific Animation we wanted it to do, we would then add the :Wait() at the end to yield until out Tween has finished playing:

local Tween = TweenService:Create(Item, Info, Goal) -- creates Tween
Tween:Play() -- Plays Tween
Tween.Completed:Wait() -- Waits until the Tween in Finished to Continue

Which is most likely what you’ll use it for.

But for the purpose of RenderStepped:Wait(), I have never seen it ever used all, At least not in the way I would think.
The one time I actually seen it being used was with this alternate method to a RenderStepped Connection, which Involves a while loop looping with the :Wait function inside:

 -- this code will work the exact same as the connection
while true do -- 'while' loop
    -- whatever here
    RunService.RenderStepped:Wait() -- waits 1/40th of a Second
end

However, this will basically overcomplicate things, on the bright side:

  • It will Only Error once
    Instead of Spamming your Output with Errors, it will only Error Once

On the Downside:

  • Yields
    this can be fixed with coroutines or task

  • Errors Once
    After that first error, it will completely stop the code, can be fixed with pcall() or xpcall() along with coroutines and task

So you should probably stick to RenderStepped:Connect()

There isnt really an exact purpose that I’m aware of besides step (or DeltaTime) which is one of the Arguments in the RenderStepped.

:frowning:
but why…

wait() isnt exactly Deprecated yet, They are probably not going to completely deprecate it anytime soon.

2 Likes