Does client fps affect runservice heartbeat?

Im trying to make a projectile script, and I was going to use RunService for it, but I didn’t know if heartbeat is affected by the client’s fps. I just wanted to know.

Depends… Is this in a server or client script?

I meant on a client script, based on the way you worded it I suppose it does?

It isn’t necessarily based on the frames per second of the client, but other factors of the client’s performance will speed up/slow down the speed of the Heartbeat listener, not by a noticeable amount though.

so i was going to make the projectile’s movement using runservice, and have like individual clients create their own copy of the projectile, won’t the “other factors” mess up the location of the projectile in its different copys?

Well, regardless of how you decide to animate it, not all the clients will be exactly the same in terms of showing the correct position of the projectile. But, it is still smart to keep the movement of the projectile on the client, especially for larger/more detailed projectiles.

To minimize this issue, here is an idea I thought of. On the SERVER, the position is created (like, the numbers) but not actually set. The server will do the math continuously and set a value to the position it wants it to be.

On the CLIENT, everytime the Heartbeat listener is fired (could be different for all clients), it will read the current value of the position that the server is setting, and set the position on the CLIENT to the value the SERVER made. Therefore, it will always be synced with the server, but the movement of the projectile itself will be based on the performance of the client.

It’s hard to put what I just said into any better words, so let me know if i need to re-explain.

I kind of understand, but from what I found, isn’t doing stuff on the server laggy? (like with projectiles) or is it just because the server is setting the projectile position.

Not always. Since in this case, the position is not actually being set by the server, and the server is simply just doing math, it should be fine.

so I can still do hit detection on the server right? or is it just better to do it on the client.

RunService.Heartbeat fires at different rates, but you can use the deltaTime parameter to get that rate. For example, if you were moving a projectile you’d move it by deltaTime*velocity. Almost all the time Heartbeat fires pretty regularly, so it’s okay to use it for important things that need to run regularly.

Yes, client FPS affects Heartbeat. The deltaTime parameter describes the time that elapsed since the last frame so you will notice difference in values depending on if the client’s FPS is higher or lower. Like the above post mentions, you can use that delta to tweak rates of change or whatever so that the code can keep up and adjust based on the client’s frame speed.

4 Likes

Well you heard the wiki. Heartbeat depends on frame and fires after it.

Use the time delta that’s parsed to the function and multiply whatever number you have with it.

So instead of this:

Hearbeat:Connect(function(delta)
    local somenumber = 5
end)

Use this:

Hearbeat:Connect(function(delta)
    local somenumber = 5
    local corrected = somenumber * 60*delta
end)

To explain what’s going on here, delta is a number representing time in seconds between the current and previous frame. If we take 60 fps as our base framerate, we’d have to multiply the delta by 60 to get exactly 1 ( 60 * 1/60 = 1). If the framerate is 2x higher, you’ll get a 2x smaller delta (60 * 1/120 = 0.5). If it’s 2x slower, you’ll get a 2x bigger delta (60 * 1/30 = 2).

If you want to use it for physics, the simplest formula would be:

pos1 = pos0 + (velocity * delta) + (acceleration/2 * delta^2)
pos0 = pos1
2 Likes

wait im still very confused, how do I even get delta time?

Its parsed through the heartbeat event as a function argument.

1 Like