Another way to get delta time / dt?

If you wanted to get dt there is a way to do it in runservice like so:

game:GetService("RunService").Hearbeat:Connect(function(dt)

But is there another way to get dt if we were to do this for example

while true do
    game:GetService("RunService").Heartbeat:Wait()
    
end

In the example I showed above how would I get the delta time / dt? Would we use tick()?

1 Like

You can just do

local Heartbeat = game:GetService("RunService").Heartbeat
while true do
    local deltaTime = Heartbeat:Wait()
end

To get the deltaTime argument.

Another way of doing it:

local waitTarget = 1

while true do
    waitedTime, _ = wait(1 / waitTarget)
end
4 Likes

So dt would just be that variable?

2 Likes

Yep! That’s the way of doing it.

Same works for any Connect / Wait comparison. Connect is non-yielding (event driven), and wait is the yielding equivalent.

2 Likes