I have a script which basically has all the things I need (not sprinting until you start moving, tween of running and stopping, animations in the stamina bar and whatnot)
But the thing is, my script has a MAJOR bug, and I don’t know how to fix it. Basically, when the player stops moving and they are still pressing on the Sprint Key, the stamina still depletes.
How do I make it so that whenever they still have their finger on the key but are not moving, the stamina doesn’t deplete?
SCRIPT:
UIS.InputBegan:Connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false and ii > runRef and humanoid.MoveDirection.Magnitude > 0 then
Bar.BackgroundColor3 = Color3.fromRGB(222, 255, 202)
TS:Create(player.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = NewWalkSpeed}):Play()
running = true
while ii > 0 and running and humanoid.MoveDirection.Magnitude > 0 do
ii = ii - .025
Bar:TweenSize(UDim2.new(ii / 10, 0, 1, 0), 'Out', 'Quint', 1.5, true)
wait()
if ii <= 0 then
Bar.BackgroundColor3 = Color3.fromRGB(255, 193, 194)
TS:Create(player.Character.Humanoid, TweenInfo.new(1.25), {WalkSpeed = NormalWalkSpeed}):Play()
end
if ii >= runRef then
Bar.BackgroundColor3 = Color3.fromRGB(222, 255, 202)
end
if ii < runRef then
Bar.BackgroundColor3 = Color3.fromRGB(255, 193, 194)
end
end
end
end)
UIS.InputEnded:Connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
TS:Create(player.Character.Humanoid, TweenInfo.new(1.25), {WalkSpeed = NormalWalkSpeed}):Play()
running = false
while ii < 10 and not running and humanoid.MoveDirection.Magnitude == 0 do
ii = ii + .035
Bar:TweenSize(UDim2.new(ii / 10, 0, 1, 0), 'Out', 'Quint', .5, true)
wait()
if ii <= 0 then
Bar.BackgroundColor3 = Color3.fromRGB(255, 193, 194)
TS:Create(player.Character.Humanoid, TweenInfo.new(1.25), {WalkSpeed = NormalWalkSpeed}):Play()
end
if ii > runRef then
Bar.BackgroundColor3 = Color3.fromRGB(222, 255, 202)
else
Bar.BackgroundColor3 = Color3.fromRGB(255, 193, 194)
end
end
end
end)