My stamina script is supposed to decrease if someone is running over the speed of 4, and increase when someone is less than the running speed of 4. But instead, the increase and decrease is running at the same time. How do I make it so it only runs separately?
local UIS = game:GetService('UserInputService')
local Bar = script.Parent:WaitForChild('Background'):WaitForChild('Bar')
local player = game.Players.LocalPlayer
local NormalWalkSpeed = 4
local NewWalkSpeed = 8
local power = 10
local sprinting = false
repeat wait() until game.Players.LocalPlayer.Character
local character = player.Character
--= Functions =--
character.Humanoid.Running:Connect(function(speed)
if power > 0 then
while speed > 4 do
if power > 0 then
power = power - .03
Bar:TweenSize(UDim2.new(power / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 42, 42), 0.001)
print("decrease")
end
wait()
end
while speed <= 4 do
if power < 10 then
power = power + .03
Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 166, 11), 0.001)
Bar:TweenSize(UDim2.new(power / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
print("gain")
end
wait()
end
else
script.Parent.Parent["Run/Walk"].TextButton.Text = "Walking"
character.Humanoid.WalkSpeed = 4
end
end)