PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

Heartbeat

The Heartbeat event fires every frame in the RunService. The step argument indicates how much time has passed between frames - usually around 1/60th of a second.

Please note that this will vary depending on the performance of the machine. If the game is only running at 40 FPS, that means that Heartbeat will fire 40 times per second, and the step argument will be roughly 1/40th of a second.

Parameters

Name Type Default Description

Indicates how much time has passed between frames


Code Samples


Printing Heartbeat Frequency

The following example will print the time between each Heartbeat loop 5 times - while the value of count is less than the value of loopCount.

local RunService = game:GetService('RunService')local loopCount = 5
local count = 0

RunService.Heartbeat:Connect(function(step)
    if count < loopCount then
        count = count + 1
        print("Time between each loop: "..step)
    end
end)