Hello!
I’m confused whether i should use a while loop or Hearbeat?
Just to be clear I don’t think there’s a best option.
But i would like to hear the benefits/drawbacks of both.
Comment if you have something to say about these statements.
Hello!
I’m confused whether i should use a while loop or Hearbeat?
Just to be clear I don’t think there’s a best option.
But i would like to hear the benefits/drawbacks of both.
Comment if you have something to say about these statements.
Well, if you need something to run every frame (very fast, about each 1/60th of a second I believe), then use heartbeat.
From what I’ve heard, the maximum speed a while loop can do is about 0.03 times a second. To go faster, you’ll have to find ways around that 60hz limit.
Info found here: How to loop faster than While true do() will let you?
Well I will assume you are talking about
while true do
wait()
end
-- Or this one
while wait() do
end
So, if your code is going to run like how I just put (basically updating it as fast as you can), I would recommend using Heartbeat HOWEVER if your loops are going to be like:
while true do
for i = 0,10,1 do
print("Timer is at..."..i)
wait(1)
end
end
Then I would recommend using the while loop, so summarizing:
Heartbeat for when you want a loop to happen really fast (Note there are also RenderStepped which can be used only in client and Stepped, for more informations you can come to this link)
While true loops for things you want to keep on repeating forever just like a round timer system. (You can also use while loops to repeat a thing until the condition is not true).