I’m debating between Heartbeat:Wait() and while wait() do. Which is more effective and which uses less memory (causing less lag hopefully) for multiple loops running at once?
Use Heartbeat:Wait()
, it strains less to the script’s thread and doesn’t jam the frame rate or any functionality, due to it being in the Task Scheduler.
For multiple loops, consider trying to execute the codes in one loop cycle if possible, unless all the loops are asynchronous or having different parameters, which executes their loops differently from each other.
Use runservice connections instead of any waits to loop
Using wait()
repeatedly isn’t precise during loops, & there’s been a huge topic on why you should avoid using wait()
if you haven’t seen it:
Using the RunService
’s Events, such as: (RenderStepped, Stepped, Heartbeat) would work better
(i recommend using heartbeat instead of renderstepped because if fps becomes unstable it slows the loop)
Yeah I’ve been using repeat loops with Heartbeat:Wait() and use ticks for timing. Just was curious if it was the right method to do.
Use the event instead, like
RunService.Heartbeat:Connect(function(delta)
end)
The delta is an optional arg to calculate delta times for timing
First I don’t think you should use :wait() you know it’s deprecated. task.wait() is the new version and its better. But secondly yeah heartbeat should put less strain on it. Sorry if I’m late.
I think you are misunderstanding what Event:Wait()
actually is. It isn’t deprecated, and the one you are referring to the global wait()
.
Oh yeah I misread sorry about that. Was kinda in a hurry.