Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How does Heartbeat work and how would I use it?

Asked by 6 years ago

How does Heartbeat work exactly and how would I use it? I've been trying to figure out how to use it for a while now, and it's only been working in studio. Can anyone give me a quick run through?

game:GetService("RunService").Heartbeat:connect(function()
    --Script here
end)

I've been treating it as if it were just a loop. Like this:

while true do
    --Script here
end

No matter what I do 'Heartbeat' just doesnt work. Only in studio.

1 answer

Log in to vote
3
Answered by
Bellyrium 310 Moderation Voter
6 years ago

RunService is what literally keeps time for games; making you jump to place when you stop lagging and must be viewed from a local script in the client not the server. Heartbeat is the FPS essentially. Frames per second. It fires every time your computer attempts to update its screen. If you are looking for a more trustworthy loop that doesn't change depending on lag, use Stepped

1
I didn't learn anything from this, but UpVoted thesit123 509 — 6y
0
Can stepped be used in a server-script? User#2146 0 — 6y
0
Both Heartbeat and Stepped can be used in a normal script. As mentioned above, only RenderStepped requires a local script for it to run. Spongocardo 1991 — 6y
Ad

Answer this question