local G=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local t=require(script.Parent.StaminaModule)local q=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local U=game.Players.LocalPlayer local O=16 local j=18 local c=24 local L=1 local Y=.1 local m=15 local g=false local X=1 local M=2 local function e()while g and t.StaminaValue.Value>0 do local G=U.Character if G then local q=G:WaitForChild("\072\117\109\097\110\111\105\100")if q.MoveDirection.Magnitude>0 then t.RemoveStamina(L)t.StaminaCanRegen=false else t.StaminaCanRegen=true end end wait(Y)end end local function Q(G,t,U)local O=TweenInfo.new(U)local j=q:Create(G,O,{WalkSpeed=t})j:Play()end G.InputBegan:Connect(function(G)if G.KeyCode==Enum.KeyCode.LeftShift then local G=U.Character if G then local q=G:WaitForChild("\072\117\109\097\110\111\105\100")if t.StaminaValue.Value>=m then Q(q,c,1)g=true t.StaminaCanRegen=false e()end end end end)G.InputEnded:Connect(function(G)if G.KeyCode==Enum.KeyCode.LeftShift then local G=U.Character if G then local q=G:WaitForChild("\072\117\109\097\110\111\105\100")Q(q,O,1)g=false wait(X)t.StaminaCanRegen=true end end end);(t.StaminaValue:GetPropertyChangedSignal("\086\097\108\117\101")):Connect(function()local G=U.Character if G then local q=G:WaitForChild("\072\117\109\097\110\111\105\100")if t.StaminaValue.Value<m and g then Q(q,j,2)end if t.StaminaValue.Value<=0 then Q(q,O,1)g=false wait(M)t.StaminaCanRegen=true end end end)
-- Shift to sprint script for Stamina System V1.
-- Delete if you don't want to use.

local UserInputService = game:GetService("UserInputService")
local StaminaModule = require(script.Parent.StaminaModule)
local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer

local defaultSpeed = 16
local belowStaminaSpeed = 18
local sprintSpeed = 24
local staminaDeductRate = 1
local staminaDeductInterval = 0.1
local minimumStaminaToSprint = 15
local sprinting = false
local regainDelay = 1
local belowStaminaDelay = 2

local function deductStamina()
	while sprinting and StaminaModule.StaminaValue.Value > 0 do
		local character = player.Character
		if character then
			local humanoid = character:WaitForChild("Humanoid")
			-- Only deduct stamina if the player is moving
			if humanoid.MoveDirection.Magnitude > 0 then
				StaminaModule.RemoveStamina(staminaDeductRate)
				StaminaModule.StaminaCanRegen = false
			else
				StaminaModule.StaminaCanRegen = true
			end
		end
		wait(staminaDeductInterval)
	end
end

local function tweenWalkSpeed(humanoid, speed, time)
	local info = TweenInfo.new(time)
	local tween = TweenService:Create(humanoid, info, { WalkSpeed = speed })
	tween:Play()
end

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		local character = player.Character
		if character then
			local humanoid = character:WaitForChild("Humanoid")
			if StaminaModule.StaminaValue.Value >= minimumStaminaToSprint then
				tweenWalkSpeed(humanoid, sprintSpeed, 1)
				sprinting = true
				StaminaModule.StaminaCanRegen = false
				deductStamina()
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		local character = player.Character
		if character then
			local humanoid = character:WaitForChild("Humanoid")
			tweenWalkSpeed(humanoid, defaultSpeed, 1)
			sprinting = false
			wait(regainDelay)
			StaminaModule.StaminaCanRegen = true
		end
	end
end)

StaminaModule.StaminaValue:GetPropertyChangedSignal("Value"):Connect(function()
	local character = player.Character
	if character then
		local humanoid = character:WaitForChild("Humanoid")
		if StaminaModule.StaminaValue.Value < minimumStaminaToSprint and sprinting then
			tweenWalkSpeed(humanoid, belowStaminaSpeed, 2)
		end
		if StaminaModule.StaminaValue.Value <= 0 then
			tweenWalkSpeed(humanoid, defaultSpeed, 1)
			sprinting = false
			wait(belowStaminaDelay)
			StaminaModule.StaminaCanRegen = true
		end
	end
end)
