Stamina goes down while not Moving

  1. What do you want to achieve? Stamina not going down while not moving and while moving then standing and holding shift, it goes back again.

  2. What is the issue? Stamina goes down while not moving and holding LeftShift

  3. What solutions have you tried so far? i have looked for the solutions on the devForum but i did not find anything that helped.

Hi, im trying to fix my Stamina UI, the problem is that the stamina goes down while standing, i want it to not go down while moving AND go back up when you stop moving WHILE holding shift.

here is the code for the Stamina:

local camera = game.Workspace.CurrentCamera
local TweeningService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local StaminaDisplay = script.Parent:WaitForChild('Background'):WaitForChild("StaminaDisplay")
local player = game.Players.LocalPlayer

local walk = 10
local run = 15

local power = 4
local sprinting = false

repeat wait() until game.Players.LocalPlayer.Character

local character = player.Character
local hum = character:WaitForChild("Humanoid")

local FOVChanges = {
	FieldOfView = 90
}

local TweenInformation = TweenInfo.new(
	1,
	Enum.EasingStyle.Quint,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local tween = TweeningService:Create(camera, TweenInformation, FOVChanges)

local FOVChanges2 = {
	FieldOfView = 70
}

local TweenInformation2 = TweenInfo.new(
	1,
	Enum.EasingStyle.Quint,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local tween2 = TweeningService:Create(camera, TweenInformation2, FOVChanges2)

UIS.InputBegan:Connect(function(key, gameProcessed)
	if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
		character.Humanoid.WalkSpeed = run
		sprinting = true
		
		while power > 0 and sprinting do
			power = power - .03
			StaminaDisplay.Size = UDim2.new(power / 5.23, 0, 0, 15)
			tween:Play()
			wait()
			
			if power <= 0 then
				character.Humanoid.WalkSpeed = walk	
			end	
		end	
		
		sprinting = false
		
		while power < 4 and not sprinting do
			
			character.Humanoid.WalkSpeed = walk
			power = power + .03
			StaminaDisplay.Size = UDim2.new(power / 5.23, 0, 0, 15)
			tween2:Play()
			wait()
			
			if power <= 0 then
				character.Humanoid.WalkSpeed = walk
			end
		end	
	end
end)

UIS.InputEnded:Connect(function(key, gameProcessed)
	if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
		character.Humanoid.WalkSpeed = walk
		sprinting = false
	end
end)

I will appreciate any help.

check this post out it’s very similar to what you have

1 Like

It is not really working. Im trying to make it so when i stop, Stamina goes back and doesnt drain, and when i was moving and then i stopped, the stamina goes back and doesnt drain

I am having the same problem here