How do I get a consistent client-sided loop?

I’ve tried renderstepped, and it takes ~1 second to get a value to 100.
I then lowered my fps cap to 30, and it took ~3.5 seconds to get to 100.
I tried while task.wait() do, but the same thing. When I lower my fps cap it slows the loop.
I don’t want to use heartbeat because I think it has to rely on the server. (correct my if I’m wrong.)
How do I get a client-sided loop that doesn’t rely on the server nor framerate?

Stick to one at a time, dont just create a bunch of topics.

Ok well I have a lot of questions that no-one seemed to ask.

btw what do you mean exactly by “Consistent Client-sided loop”?

so from what im reading, you want a loop to continue without FPS slowing it, not sure if thats possible

a loop that runs in a local script that doesn’t rely on the server

That’s a completely different question and belongs in a different thread.

The solution here is delta time, the first parameter of RenderStepped. It represents the elapsed time in seconds since the last frame, so it scales with FPS. At a theoretically stable and unchanging FPS of 55, it will be 1/55 of a second. Multiply it with number to make that number ‘per second’.

    num += 100 * dt -- 100 per second
1 Like

Well I don’t need a value to reach 100 in one second, it’s going to be used for things like tweens, and more complex than just values.

You can’t guarantee that anything happens exactly on time. That’s the nature of lag. The best you can do is use dt to compensate for it, or use task.wait with a more forgiving delay such as 0.1

1 Like

You answered it yourself, create a loop in a local script and it will run on the client.

The server and client share the load for physics simulation. Each one has their own independent Heartbeat/Stepped events. If you use either in a LocalScript it will be client-side.

What @JarodOfOrbiter said is completely correct. RenderStepped, BindToRenderStep, Heartbeat, Stepped, a while loop with a task.wait() (which returns the actual time it took!)—no matter what your loop is, you are fundamentally not guaranteed a consistent time step and have to scale whatever effect you have by the actual delta time.

1 Like