RunningService.HeartBeat:Connect() vs while task.wait() do

Are these same?

RunningService.HeartBeat:Connect(function()
    -- Code
end)
while task.wait() do
    -- Code
end
1 Like

Task.wait() is the same as RunningService.HeartBeat:Wait()

while task.wait() do is considered a bad practice, despite task.wait() being the same as RunService.HeartBeat:Wait()

Use RunService.HeartBeat instead of while task.wait() do.

In addition to what @black1shadow1048 and @ValiantWind have said,

Take a look here : How does RunService work?

if you want to know how to use RunService and When to use it.

Adding on, you should use heartbeat events for fast loops