Why is my client Heartbeat:Wait() going so fast?

This morning I was experimenting with some run service functionality to change incrementation based on client FPS. Upon some testing, I noticed some extremely odd behavior from Heartbeat:Wait(). My “FPS” is through the roof with :Wait(), but with :Connect() its normal. Here is an example of what I mean

Using this code, I’m getting results of around 7000-8000 FPS which is definitely inaccurate.

local RS = game:GetService("RunService")
while wait(1) do
  local ST = tick()
  RS.Heartbeat:Wait()
  local FPS = 1/(tick() - ST)
  print(FPS)
end

Result:
image

Method 2 gives me normal results of around 60 FPS

local Int = 0
RS.Heartbeat:Connect(function()
  Int = Int + 1
end)

while wait(1) do
  print(Int)
  Int = 0
end

Result:
image

Something to note is that if I change Heartbeat to RenderStepped Method 1 shows normal results.
image

For my use case I’d like to be able to use method 1. Does anyone know why method 1 acts the way it does?

It’s likely because when you :Wait() for heartbeat, its not necessarily at the end of the previous frame, meaning you could be starting tick() halfway through the frame, giving you a super high FPS.

to fix this, just replace wait(1) with true so it runs as each frame passes giving you a more accurate result.

3 Likes