Hello guys, I am very new, so I apologize in advance if I am annoying for asking this, however, I am having trouble fixing this, if fixable. Basically, the script works very well, I do have some stuff to modify, but that’s not the concern here.
The issue is that the stamina drain increases as the game’s FPS goes up. The drain is like 10x smaller if I run at 30 FPS, compared to when I run at 175 FPS. What can I do about this issue?
Consists of a “Handler” local script and inside of it, two more local scripts for the sprint states, “Running” and “NotRunning”.
Handler:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local Player = Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local StaminaGui = script.Parent
local Holder = StaminaGui:WaitForChild("Holder")
local Bar = Holder:WaitForChild("Bar")
local Stamina = script.Stamina
local TI = TweenInfo.new(0.01, Enum.EasingStyle.Quint)
UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift and Humanoid.MoveDirection.Magnitude > 0 then
if Stamina.Value >= 1 then
Humanoid.WalkSpeed = 16
script.Running.Enabled = true
script.NotRunning.Enabled = false
end
end
end)
UserInputService.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
Humanoid.WalkSpeed = 8
script.Running.Enabled = false
script.NotRunning.Enabled = true
end
end)
while task.wait() do
if Stamina.Value < 100 then
TweenService:Create(Bar, TI, {Size = UDim2.new(Stamina.Value / 100, 0, 1, 0)}):Play()
end
end
Running:
local Stamina = script.Parent.Stamina
while task.wait() do
if Stamina.Value > 0 then
repeat
task.wait()
Stamina.Value = Stamina.Value - 0.25
until Stamina.Value <= 0
end
end
NotRunning:
local Stamina = script.Parent.Stamina
while task.wait() do
if Stamina.Value < 100 then
repeat
task.wait()
Stamina.Value = Stamina.Value + 0.05
until Stamina.Value >= 100
end
end