Hello! So I was creating a stamina system for my game, which required a tutorial because I am not the best at scripting. Anyways, I noticed something strange when testing the system out. Since RunService.Heartbeat is based on frames, changing the fps on Roblox using the new feature significantly impacts the stamina mechanism. I have attached a video below showing the problem. Since my game is somewhat competitive, having a lower fps grants the player significantly more stamina than someone with a higher fps.
So my question is, what alternatives are there for my server script. I wanted to use a while task.wait(0.1) do however it does not look as smooth as heart beat, and I really don’t want to add yet another while true do loop to my game. Any suggestions?
Heartbeat fires with the elapsed time since the previous frame. You can multiply this value against your stamina cost per second while running, to drain the stamina at a consistent rate, independent of FPS.
Delta-time is a precise value. So if a tenth of a second passed since the last frame, it would be 0.1. So if your stamina cost per second was 1, the resulting stamina loss for that frame after multiplying these two values together, would correctly be 0.1.