-- // Constants \\ --

local defaultSpeed = 16
local sprintSpeed = 22
local normalFov = 70
local sprintFov = 80
local staminaDrainRate = 20
local staminaFillRate = 30
local staminaRegenDelay = 0.5
local crouchSpeed = 8
local normalSpeed = 16
local crouchHeight = 1.5
local normalHeight = 2
local stamina = script.Parent.stamina.Value
local maxStamina = 100
local minStamina = 0


-- [ Services ] --

local Services = setmetatable({}, {__index = function(Self, Index)
	local NewService = game:GetService(Index)
	if NewService then
		Self[Index] = NewService
	end
	return NewService
end})

local UserInputService = Services.UserInputService
local TweenService = Services.TweenService
local RunService = Services.RunService
local Players = Services.Players
local ReplicatedStorage = Services.ReplicatedStorage


-- // Variables \\ --
local variables = script.Parent.Variables
local sprintKey = Enum.KeyCode.LeftShift
local crouchKey = Enum.KeyCode.C
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Camera = workspace.CurrentCamera
local sprintAnim = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Player"):WaitForChild("SprintAnim")
local animTrack = Humanoid:LoadAnimation(sprintAnim)
--local crouchIdleAnimation = Humanoid:LoadAnimation(script.CrouchIdle)
--local crouchWalkAnimation = Humanoid:LoadAnimation(script.CrouchWalk)
local healthBar = game.Players.LocalPlayer.PlayerGui:WaitForChild("StaminaAndHealthBar").Frame.HealthBar.Bar
local staminaBar = game.Players.LocalPlayer.PlayerGui:WaitForChild("StaminaAndHealthBar").Frame.StaminaBar.Bar
local shiftPressed = false
local movementKeysPressed = {}
local staminaDepleted = false
local sprinting = variables.Sprinting.Value
local isCrouching = variables.Crouching.Value
local isMoving = false
local lastSprintTime = tick()
local movementKeys = {Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D}


-- // Functions \\ --

local function tweenFov(duration, fov)
	local tween = TweenService:Create(Camera, TweenInfo.new(duration, Enum.EasingStyle.Quad), { FieldOfView = fov })
	tween:Play()
	tween.Completed:Wait()
	tween:Destroy()
end

local function tweenStaminaBar()
	local tween = TweenService:Create(staminaBar, TweenInfo.new(0.25, Enum.EasingStyle.Quad), { Size = UDim2.new(stamina / maxStamina, 0, 1, 0) })
	tween:Play()
end

local function startSprinting()
	if not sprinting and stamina > minStamina and not isCrouching then
		sprinting = true
		Humanoid.WalkSpeed = sprintSpeed
		animTrack:Play()
		tweenFov(0.25, sprintFov)
	end
end

local function stopSprinting()
	if sprinting then
		sprinting = false
		Humanoid.WalkSpeed = defaultSpeed
		animTrack:Stop()
		tweenFov(0.25, normalFov)
	end
end

local function crouch()
	if not isCrouching and not sprinting then
		isCrouching = true
		Humanoid.WalkSpeed = crouchSpeed
		HumanoidRootPart.Size = Vector3.new(HumanoidRootPart.Size.X, crouchHeight, HumanoidRootPart.Size.Z)
		if isMoving then
			--crouchIdleAnimation:Stop()
			--crouchWalkAnimation:Play()
		else
			--crouchWalkAnimation:Stop()
			--crouchIdleAnimation:Play()
		end
	end
end

local function stand()
	if isCrouching then
		isCrouching = false
		Humanoid.WalkSpeed = normalSpeed
		HumanoidRootPart.Size = Vector3.new(HumanoidRootPart.Size.X, normalHeight, HumanoidRootPart.Size.Z)
		--crouchIdleAnimation:Stop()
		--crouchWalkAnimation:Stop()
	end
end


-- // Main \\ --

--script.Parent.PlayerName.Text = Player.Name
--script.Parent.PlayerThumb.Image = "rbxthumb://type=AvatarHeadShot&id=" .. Player.UserId .. "&w=420&h=420"

Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	healthBar.Size = UDim2.new(Character.Humanoid.Health / 100, 0, 1, 0)
end)

UserInputService.InputBegan:Connect(function(input, processed)
	if processed then return end
	if input.KeyCode == sprintKey then
		if not staminaDepleted then
			shiftPressed = true
			if next(movementKeysPressed) ~= nil then
				startSprinting()
			end
		end
	elseif table.find(movementKeys, input.KeyCode) then
		movementKeysPressed[input.KeyCode] = true
		if shiftPressed and not staminaDepleted and not isCrouching then
			startSprinting()
		end
	elseif input.KeyCode == crouchKey and not isCrouching and not sprinting then
		crouch()
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == sprintKey then
		shiftPressed = false
		stopSprinting()
		if not UserInputService:IsKeyDown(sprintKey) then
			staminaDepleted = false
		end
	elseif table.find(movementKeys, input.KeyCode) then
		movementKeysPressed[input.KeyCode] = nil
		if next(movementKeysPressed) == nil then
			stopSprinting()
		end
	elseif input.KeyCode == crouchKey then
		stand()
	end
end)

RunService.RenderStepped:Connect(function(deltaTime)
	if sprinting then
		stamina = math.max(minStamina, stamina - staminaDrainRate * deltaTime)
		if stamina <= minStamina then
			staminaDepleted = true
			stopSprinting()
		end
		lastSprintTime = tick()
	else
		if tick() - lastSprintTime >= staminaRegenDelay then
			stamina = math.min(maxStamina, stamina + staminaFillRate * deltaTime)
		end
	end
	tweenStaminaBar()
end)

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if Humanoid.MoveDirection.Magnitude > 0 then
		isMoving = true
		if isCrouching then
			--crouchIdleAnimation:Stop()
			--if not crouchWalkAnimation.IsPlaying then
			--	crouchWalkAnimation:Play()
			--end
		end
	else
		isMoving = false
		if isCrouching then
			--crouchWalkAnimation:Stop()
			--if not crouchIdleAnimation.IsPlaying then
			--	crouchIdleAnimation:Play()
			--end
		end
	end
end)


local anim = game.ReplicatedStorage.Animations.Player.Land
local playAnim = script.Parent.Parent.Humanoid:LoadAnimation(anim)

local isJumping = false

Humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping then
		if animTrack.IsPlaying then
			animTrack:Stop()
		end
	elseif newState == Enum.HumanoidStateType.Landed then
		if animTrack.IsPlaying then
			animTrack:Stop()
		end
		playAnim:Play()
		playAnim.Stopped:Wait()
		if sprinting then
			animTrack:Play()
		end
	elseif newState == Enum.HumanoidStateType.Freefall then
		if animTrack.IsPlaying then
			animTrack:Stop()
		end
	end
end)



modify this localscript to use this:

local StaminaManager = {}

local stamina = 100
local maxStamina = 100
local minStamina = 0

function StaminaManager.GetStamina()
	return stamina
end

function StaminaManager.AddStamina(amount)
	stamina = math.min(maxStamina, stamina + amount)
end

function StaminaManager.ReduceStamina(amount)
	stamina = math.max(minStamina, stamina - amount)
	if stamina <= minStamina then
		return false
	end
	return true
end

return StaminaManager