I have been using RunService.Heartbeat instead of while loops for a long time now, but I never really understood the difference. I took a look at the Developer Hub to check out the description and noticed that RunService has a lot more than just heartbeat.
What is the difference?
And what are some examples of when one should be used over the others?
While do is basically just an infinite loop.
RunService.Heartbeat is an event that fires every time after a physics simulation was completed (in a frame i believe)
RunService.Stepped is an event that fires every time a physics simulation is about to begin
RunService.RenderStepped is an event that fires every time a new frame is about to render
Well I have mainly been using Runservice:BindToRenderStep() because priority a is before 2, and also because I can run somthing before the camera and input or after input and before camera. and physics crap also RenderPriorities
BindToRenderStep has priorities which is here RenderPriority | Roblox Creator Documentation
RenderStepped and BindToRenderStepped are running during the frame before screen drawing, and Stepped and Heartbeat are after the frame is rendered which is why You dont want to use them if you dont want to be 1 frame behind.
But Stepped should be called to update Motor6Ds.
Heartbeat is the almost the last thing called and After the frame is rendered.