Why Heartbeat making different?

RunService = game:GetService("RunService")

while true do
	local Tick = tick()
	RunService.Heartbeat:Wait()
	print(tick()-Tick)
end

this printing
18:56:38.282 0.017619609832763672 - Server - Script:6
18:56:38.297 0.014919519424438477 - Server - Script:6
18:56:38.314 0.0166475772857666 - Server - Script:6
18:56:38.331 0.0168304443359375 - Server - Script:6
18:56:38.393 0.06191563606262207 - Server - Script:6

RunService = game:GetService("RunService")

while wait(1) do
	local Tick = tick()
	RunService.Heartbeat:Wait()
	print(tick()-Tick)
end

this printing
18:59:27.057 0.00027441978454589844 - Server - Script:6
18:59:28.059 0.0002391338348388672 - Server - Script:6
18:59:29.074 0.00033783912658691406 - Server - Script:6
18:59:30.089 0.00024580955505371094 - Server - Script:6
18:59:31.091 0.00026416778564453125 - Server - Script:6

why so big difference?

1 Like
RunService = game:GetService("RunService")

local Tick = tick()
RunService.Stepped:Wait()
print(tick()-Tick)

this print
0.12743854522705078

i need this BIG(0.1~0.15) result when using while or wait()

1 Like

:joy:I can’t really think of an explanation for this kind of question.

May be because you’re printing delta time in the snippet that’s not using wait(1)

wait resumes the script on a Stepped event. Since Heartbeat happens right after Stepped, it makes sense that the delta is smaller.

Basically, the first snippet is measuring the distance between one Heartbeat and the next - which as you can see is roughly 60 FPS. The second snippet is measuring the distance between Stepped and Heartbeat, which is smaller because it’s measuring the start and end of one frame, rather than the end of one frame to the end of the next.

If you use task.wait instead of wait, you will see that it looks identical to your first snippet: 60 FPS. Why? Because task.wait resumes immediately after Heartbeat fires, you’ll once again be measuring the distance between two Heartbeats.

you mean while task.wait(1) do ?
but this printing same as while wait(1) do

can you script it please?

Yep

It shouldn’t.

local runService = game:GetService('RunService')

while true do
	task.wait(1)
	local clock = os.clock()
	runService.Heartbeat:Wait()
	print(os.clock() - clock)
end

But oh interesting, I was told that task.wait resumes on Heartbeat, but for me it’s still printing incredibly low numbers like 0.000035999983083456755. Guess I was wrong there.

yeh this still printing 0.000026500001695239916 ;-;

But why is this a problem? I explained to you what is happening. If Figma will start working instead of being a useless piece of crap I can make an explanatory image.

i need to slow my visible movement.
cause the visible movement is faster then physics process.
and the difference between visible movement and physics process is 0.1~0.15 second

so as i said it have to get time same as Why Heartbeat making different? - #2 by BuilderBird_Dev

So here’s what’s happening.

Take a look at this chart. It graphs timing data collected by a Script. As you can see, the distance between a Stepped and Heartbeat is only about 0.1ms, which is around 0.0001 seconds, which is around what you observed. The difference between the first and second Stepped is ~16.75ms, or 0.01675s, also close to what you observed. Same with the Heartbeats.

Obviously a huge chunk of time is cut out of this chart due to just HOW HUGE 16ms is at this scale.