I fixed my client sided stamina sprint system yesterday, the stamina would not regenerate on mobile devices but it regenerates fine on PC and in the studio. The error was in the line:
Stamina.Value = Stamina.Value + (RegenRate * DeltaTime)
If the RegenRate is less than 30 it stops functioning on mobile but works on PC and in the studio. This is my first use of heartbeat and deltaTime, can anyone explain why this happens? I want the stamina to charge much slower than it is consumed to incentivize not using it, or only using it when extra combat help is needed.
It is a local script in starter Character (starter player wouldn’t work after player died.)
This is full excerpt of the script:
RunService.Heartbeat:Connect(function(DeltaTime) local Stamina = player.Stamina if Sprinting then if Stamina.Value > 0 then Stamina.Value = Stamina.Value - DrainRate * DeltaTime else sprint(false) Exhausted = true end elseif Stamina.Value < MaxStamina.Value then Stamina.Value = Stamina.Value + (RegenRate * DeltaTime) --THIS IS WHERE THE PROBLEM HAPPENS if Stamina.Value > RunRefresh then -- we can now run again! Exhausted = false if SprintHeld then -- resume running because player is still holding down the sprint key! sprint(SprintHeld) end end end end)
Any advice is much appreciated!