Delta Time using Task.wait() Question

For a game design project, I’m trying to use delta time, which is the amount of time between the last frame and the current frame. For my setup, I’m using task.wait(), as according to the documentation, it returns the “actual amount of time elapsed” (Documentation).

This is my setup for calculating delta time:

According to my calculations, at 60 FPS, task.wait() should be returning 1/60, or 0.01666667.

However, when I print the value returned by task.wait():
image

Roblox cannot run faster than 60 FPS without an FPS unlocker, so why is the recorded time shorter than 1/60th of a second?

1 Like

That’s right, task.wait() yield time is identical to RunService.Heartbeat:Wait() and depends on the refresh rate.

Looks like you are attempting to yield for one frame inside a Stepped or RenderStepped connection, which actually works properly, but results in these confusingly small numbers.

There’s a simple explanation to it though: the function is called before Heartbeat, so the task.wait() is resumed later in the same frame.

You shouldn’t even need to ever yield before Heartbeat. If anything, the yielding can cause lag in screen drawing and other prioritised tasks.

For updating CFrames, avoid causing any delays in rendering, camera, character, and other updates using Heartbeat and the automatically provided delta time. Most base parts ought to have their CFrame updated in the physics simulation phase.

game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.