Hello, I’m using the RunService as a game loop to update certain stats like walkspeed and stamina regen. (On the server, not client)
Is using RunService.Stepped or let’s say, .Heartbeat on the server guranteed 60 times calling the function in 1 second, or at least close to that?
Are there any efficient methods to make our code run 60 FPS even when server lag is present?
While achieving a consistent 60 FPS in the presence of server lag can be challenging, there are methods to mitigate the impact. By minimizing server-client communication and optimizing scripts, you can reduce the likelihood of server lag occurring. These techniques can significantly improve performance and are often considered the best approach in such situations.
You can use the delta time (the time since last
Heartbeat for example) to make sure things are consistent
For example this is how a basic health regen script would look like:
local RunService = game:GetService("RunService")
local HEALTH_PER_SECOND = 5
local humanoid = some_humanoid -- This variable should be a humanoid of the character you want to regen hp to
humanoid.Health = humanoid.Health + HEALTH_PER_SECOND * delta
This will be consistent because the
delta variable is the time since last
Heartbeat was fired, so if the server lags for 2 seconds for example then you will get
HEALTH_PER_SECOND * 2 health