Help with Heartbeat DeltaTime

I use runservice.heartbeat(delta) to move a part
However, if the server fps lags just for a few seconds, that lag would cause the part to move a bigger distance, and be completely off track (presumably due to the delta being higher)
How could I fix this?

local speed = 10 -- does not matter

runService.Heartbeat:Connect(function(delta)
    local moveInt = speed * delta
end)

If you want the part to move a set distance each step (irrespective of time) then use:

local moveInt = speed

The use of delta time, in this context, would give a part a constant ‘apparent’ speed irrespective of the number of steps used to render that speed. In other words it would move a set distance in the time given, as opposed to being dependent on the number of steps made.

1 Like

It really depends on what you are trying to achieve in your game.
Having a larger delta time after a lag is normal, as a constantly moving object would be farther along after a lag.

If it is a jarring sort of jump you are seeing, you need to tween from your current position to the position it would be after the lag. You can use delta time to see how far the character ‘should’ be, and tween to that position.

maybe speed / 60 ? does heartbeat run at 60 fps?

It aims to run at 60 steps per second, but this is not exact as each step could take a different amount of time depending on the amount of work it needs to do each step. This is why delta time is important, as there is no way to know beforehand how long any step will take, only the amount of time it did take.