I apologize if this is a redundant post as this question doesn’t have major importance, but I wanted extra clarification on the matter.
On pretty much every post that I see asking for the difference between RunService Heartbeat and While Loops, I always see the same response that they are different because while loops are slower.
This should be inherently false, because task.wait() is the same as waiting on heartbeat:
while true do
task.wait() -- same as one heartbeat - Right?
print("New Frame")
end
-- In theory are identical
game["Run Service"].Heartbeat:Connect(function()
print("New Frame")
end)
I’m looking for somebody to confirm whether that’s true or false.
Now the one advantage that heartbeat serves regardless if it’s inherently the same as while loops, is delta time, because it allows you to equalize stuff with different frame rates etc:
while true do
timeSpent += 1 -- Will update faster on higher frame rates
task.wait()
end
game["Run Service"].Heartbeat:Connect(function(dt)
timeSpent += dt -- Will update at the same rate on all frame rates
end)