local N=Color3.new(.619608,.0588235,0)local p=Color3.new(0,.666667,1)local f=Color3.new(0,.666667,1)local B={}do function B.IsTouchDevice()return UserInputService.TouchEnabled end function B.Create(N)return function(p)local f=Instance.new(N)for N,p in pairs(p)do if type(N)=="\110\117\109\098\101\114"then p.Parent=f else f[N]=p end end return f end end function B.Clamp(N,p,f)return math.max(N,math.min(p,f))end function B.DisconnectEvent(N)if N then N:disconnect()end return nil end function B.SetGUIInsetBounds(N,p,f,B)GuiService:SetGlobalGuiInset(N,p,f,B)end local N={}function B.FindPlayerHumanoid(p)local f=p and p.Character if f then local B=N[p]if B and B.Parent==f then return B else N[p]=nil for f,B in pairs(f:GetChildren())do if B:IsA("\072\117\109\097\110\111\105\100")then N[p]=B return B end end end end end end walking.Changed:Connect(function()if walking.Value==false then SprintingValue.Value=false BreathRunningStop:Play()elseif walking and Sprinting==true then SprintingValue.Value=true end end)UIS.InputBegan:Connect(function(N)if N.KeyCode==Enum.KeyCode.LeftShift then repeat wait()until Sprinting==false if Sprinting==false and(Stamina.Value>StaminaReductionRate and script.LoadingBcsTAMINAis0.Value==false)then(TS:Create(plr.Character.Humanoid,TweenInfo.new(3),{WalkSpeed=SprintSpeed})):Play()Sprinting=true if walking.Value==true then SprintingValue.Value=true end repeat wait(StaminaReductionDelay)if walking.Value==true and SprintingValue.Value==true then Stamina.Value-=StaminaReductionRate end until Sprinting==false;(TS:Create(plr.Character.Humanoid,TweenInfo.new(1.2),{WalkSpeed=OriginalWalkSpeed})):Play()end end end)UserInputService.InputEnded:connect(function(N)if N.KeyCode==Enum.KeyCode.LeftShift then if Sprinting==true or walking.Value==false then Sprinting=false SprintingValue.Value=false;(TS:Create(plr.Character.Humanoid,TweenInfo.new(1.2),{WalkSpeed=OriginalWalkSpeed})):Play()end end end)if UserInputService.TouchEnabled then StaminaButton.Visible=true end StaminaButton.Button.MouseButton1Down:Connect(function()if Sprinting==false and(Stamina.Value>StaminaReductionRate and script.LoadingBcsTAMINAis0.Value==false)then Border.Color=Color3.new(1,1,1)Sprinting=true;(TS:Create(plr.Character.Humanoid,TweenInfo.new(3),{WalkSpeed=SprintSpeed})):Play()if walking.Value==true then SprintingValue.Value=true end repeat wait(StaminaReductionDelay)if walking.Value==true and SprintingValue.Value==true then Stamina.Value-=StaminaReductionRate end until Sprinting==false;(TS:Create(plr.Character.Humanoid,TweenInfo.new(1.2),{WalkSpeed=OriginalWalkSpeed})):Play()elseif Sprinting==true and Stamina.Value<100 then BreathRunningStop:Play()Border.Color=Color3.new(0,0,0)SprintingValue.Value=false Sprinting=false;(TS:Create(plr.Character.Humanoid,TweenInfo.new(1.2),{WalkSpeed=OriginalWalkSpeed})):Play()end end)Stamina.Changed:connect(function(P)if P<StaminaReductionRate then Sprinting=false SprintingValue.Value=false end local y=script.Parent:WaitForChild("\070\114\097\109\101\095\066\097\114")local M=script.Parent.Frame_Bar:WaitForChild("\070\114\097\109\101\095\066\097\114\070\105\108\108")M:TweenSize(UDim2.new(P/100,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quart,.5,true)local J={[Vector3.new(N.r,N.g,N.b)]=.1,[Vector3.new(p.r,p.g,p.b)]=.5;[Vector3.new(f.r,f.g,f.b)]=.8}local A=.1 local Z=N local x=.8 local H=f local function Y(N)if N<A then return Z elseif N>x then return H end local p=Vector3.new(0,0,0)local f=0 for B,P in pairs(J)do local y=N-P if y==0 then return Color3.new(B.x,B.y,B.z)else local N=1/(y*y)p=p+N*B f=f+N end end local B=p/f return Color3.new(B.x,B.y,B.z)end local g=Stamina.Value/100 if Stamina.Value<3 then Border.Color=Color3.new(0,0,0);(TS:Create(plr.Character.Humanoid,TweenInfo.new(1.2),{WalkSpeed=OriginalWalkSpeed})):Play()end g=B.Clamp(0,1,g)local a=Y(g)M.BackgroundColor3=a if Stamina.Value>99 then script.LoadingBcsTAMINAis0.Value=false;(SprintGui:WaitForChild("\070\114\097\109\101\095\066\097\114")):TweenPosition(UDim2.new(.5,0,1,(SprintGui:WaitForChild("\070\114\097\109\101\095\066\097\114")).AbsoluteSize.Y+1),Enum.EasingDirection.Out,Enum.EasingStyle.Quart,.75,true)else(SprintGui:WaitForChild("\070\114\097\109\101\095\066\097\114")):TweenPosition(UDim2.new(.5,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quart,.25,true)if Stamina.Value<40 then BreathRunning:Play()elseif Stamina.Value>41 then BreathRunningStop:Play()end end end)SprintingValue.Changed:Connect(function()if SprintingValue.Value==false then script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=false wait(.01)script.CanFill.Value=true end end)Stamina.Changed:Connect(function()if Stamina.Value<0 then Stamina.Value=0 elseif Stamina.Value>=100 then Stamina.Value=100 end end)Stamina.Changed:Connect(function()if Stamina.Value<3 then script.LoadingBcsTAMINAis0.Value=true elseif Stamina.Value>=98 then script.LoadingBcsTAMINAis0.Value=false end end)while true do wait(RegenerateDelay)if SprintingValue.Value==false and(Stamina.Value<100 and script.CanFill.Value==true)then Stamina.Value=Stamina.Value+RegenerateValue end end

local Stamina_Red_Color = Color3.new(0.619608, 0.0588235, 0)
local Stamina_Yellow_Color = Color3.new(0, 0.666667, 1)
local Stamina_Green_Color = Color3.new(0, 0.666667, 1)


local Util = {}
do
	function Util.IsTouchDevice()
		return UserInputService.TouchEnabled
	end

	function Util.Create(instanceType)
		return function(data)
			local obj = Instance.new(instanceType)
			for k, v in pairs(data) do
				if type(k) == 'number' then
					v.Parent = obj
				else
					obj[k] = v
				end
			end
			return obj
		end
	end

	function Util.Clamp(low, high, input)
		return math.max(low, math.min(high, input))
	end

	function Util.DisconnectEvent(conn)
		if conn then
			conn:disconnect()
		end
		return nil
	end

	function Util.SetGUIInsetBounds(x1, y1, x2, y2)
		GuiService:SetGlobalGuiInset(x1, y1, x2, y2)
	end

	local humanoidCache = {}
	function Util.FindPlayerHumanoid(player)
		local character = player and player.Character
		if character then
			local resultHumanoid = humanoidCache[player]
			if resultHumanoid and resultHumanoid.Parent == character then
				return resultHumanoid
			else
				humanoidCache[player] = nil -- Bust Old Cache
				for _, child in pairs(character:GetChildren()) do
					if child:IsA('Humanoid') then
						humanoidCache[player] = child
						return child
					end
				end
			end
		end
	end
end


walking.Changed:Connect(function()
	if walking.Value == false then
		
		
		SprintingValue.Value = false
		BreathRunningStop:Play()
		
	elseif walking and Sprinting == true then
		SprintingValue.Value = true
	
		
	end
end)

UIS.InputBegan:Connect(function(key)
	
	if key.KeyCode == Enum.KeyCode.LeftShift  then
		repeat wait() until Sprinting == false
		if (Sprinting == false) and (Stamina.Value > StaminaReductionRate) and script.LoadingBcsTAMINAis0.Value == false then
				   TS:Create(plr.Character.Humanoid, TweenInfo.new(3), {WalkSpeed = SprintSpeed}):Play()
			Sprinting = true
			if walking.Value == true then


				SprintingValue.Value = true
			end
			repeat wait(StaminaReductionDelay)
				if walking.Value == true and SprintingValue.Value == true then
					Stamina.Value -= StaminaReductionRate
				end
			until Sprinting == false
			TS:Create(plr.Character.Humanoid, TweenInfo.new(1.2), {WalkSpeed = OriginalWalkSpeed}):Play()
		end
	end	
end)

UserInputService.InputEnded:connect(function(inputkey)
	
	if inputkey.KeyCode == Enum.KeyCode.LeftShift then
		if Sprinting == true or walking.Value == false then
	
			Sprinting = false
			SprintingValue.Value = false
			
			TS:Create(plr.Character.Humanoid, TweenInfo.new(1.2), {WalkSpeed = OriginalWalkSpeed}):Play()
			
			end
		
	end
end)

if UserInputService.TouchEnabled then
	StaminaButton.Visible = true
end

StaminaButton.Button.MouseButton1Down:Connect(function()
	if (Sprinting == false) and (Stamina.Value > StaminaReductionRate) and script.LoadingBcsTAMINAis0.Value == false then
		Border.Color = Color3.new(1, 1, 1)
		Sprinting = true
		TS:Create(plr.Character.Humanoid, TweenInfo.new(3), {WalkSpeed = SprintSpeed}):Play()
		if walking.Value == true then
			

			SprintingValue.Value = true
		end
		repeat wait(StaminaReductionDelay)
			if walking.Value == true and SprintingValue.Value == true then
				Stamina.Value -= StaminaReductionRate
			end
		until Sprinting == false
		TS:Create(plr.Character.Humanoid, TweenInfo.new(1.2), {WalkSpeed = OriginalWalkSpeed}):Play()
	elseif Sprinting == true and Stamina.Value < 100  then
		BreathRunningStop:Play()
		Border.Color = Color3.new(0, 0, 0)
		SprintingValue.Value = false
		Sprinting = false
		
		TS:Create(plr.Character.Humanoid, TweenInfo.new(1.2), {WalkSpeed = OriginalWalkSpeed}):Play()
	end
end)


Stamina.Changed:connect(function(value)
	if (value < StaminaReductionRate) then
		Sprinting = false
		SprintingValue.Value = false
	end
	local Bar = script.Parent:WaitForChild('Frame_Bar')
	local Fill = script.Parent.Frame_Bar:WaitForChild('Frame_BarFill')
	Fill:TweenSize(UDim2.new(value/100,0,1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, .5, true)

	local healthColorToPosition = {
		[Vector3.new(Stamina_Red_Color.r, Stamina_Red_Color.g, Stamina_Red_Color.b)] = 0.1;
		[Vector3.new(Stamina_Yellow_Color.r, Stamina_Yellow_Color.g, Stamina_Yellow_Color.b)] = 0.5;
		[Vector3.new(Stamina_Green_Color.r, Stamina_Green_Color.g, Stamina_Green_Color.b)] = 0.8;
	}
	local min = 0.1
	local minColor = Stamina_Red_Color
	local max = 0.8
	local maxColor = Stamina_Green_Color

	local function HealthbarColorTransferFunction(staminaPercent)
		if staminaPercent < min then
			return minColor
		elseif staminaPercent > max then
			return maxColor
		end

		local numeratorSum = Vector3.new(0,0,0)
		local denominatorSum = 0
		for colorSampleValue, samplePoint in pairs(healthColorToPosition) do
			local distance = staminaPercent - samplePoint
			if distance == 0 then
				return Color3.new(colorSampleValue.x, colorSampleValue.y, colorSampleValue.z)
			else
				local wi = 1 / (distance*distance)
				numeratorSum = numeratorSum + wi * colorSampleValue
				denominatorSum = denominatorSum + wi
			end
		end
		local result = numeratorSum / denominatorSum
		return Color3.new(result.x, result.y, result.z)
	end
	local staminaPercent = Stamina.Value / 100
	
	if Stamina.Value < 3 then
		Border.Color = Color3.new(0, 0, 0)
		
		
		
		TS:Create(plr.Character.Humanoid, TweenInfo.new(1.2), {WalkSpeed = OriginalWalkSpeed}):Play()
	
	end
	
	staminaPercent = Util.Clamp(0, 1, staminaPercent)
	local staminaColor = HealthbarColorTransferFunction(staminaPercent)
	Fill.BackgroundColor3 = staminaColor
	
	if Stamina.Value > 99 then
		script.LoadingBcsTAMINAis0.Value = false
		SprintGui:WaitForChild("Frame_Bar"):TweenPosition(UDim2.new(0.5, 0, 1, SprintGui:WaitForChild("Frame_Bar").AbsoluteSize.Y + 1), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 0.75, true)
	else
		SprintGui:WaitForChild("Frame_Bar"):TweenPosition(UDim2.new(0.5, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 0.25, true)
		
	
		if Stamina.Value < 40 then
	         BreathRunning:Play()
		elseif Stamina.Value > 41 then
			BreathRunningStop:Play()
		end
	
	end
end)
SprintingValue.Changed:Connect(function()
	if SprintingValue.Value == false then
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = false
		wait(0.01)
		script.CanFill.Value = true
	end
end)


Stamina.Changed:Connect(function()
	if Stamina.Value < 0 then
		Stamina.Value = 0
	elseif Stamina.Value >= 100 then
		Stamina.Value = 100

	end
end)
Stamina.Changed:Connect(function()
	if Stamina.Value < 3 then
		script.LoadingBcsTAMINAis0.Value = true
	elseif Stamina.Value >= 98 then
		script.LoadingBcsTAMINAis0.Value = false

	end
end)

while true do
	wait(RegenerateDelay)
	if (SprintingValue.Value == false) and (Stamina.Value < 100) and (script.CanFill.Value == true) then
		Stamina.Value = Stamina.Value + RegenerateValue
	end
end

