local w=Color3.new(1.0,.10980392156863,.0)local G=Color3.new(.98039215686275,.92156862745098,0)local l=Color3.new(.10588235294118,.98823529411765,.41960784313725)local T={}do function T.IsTouchDevice()return UserInputService.TouchEnabled end function T.Create(w)return function(G)local l=Instance.new(w)for w,G in pairs(G)do if type(w)=="\110\117\109\098\101\114"then G.Parent=l else l[w]=G end end return l end end function T.Clamp(w,G,l)return math.max(w,math.min(G,l))end function T.DisconnectEvent(w)if w then w:disconnect()end return nil end function T.SetGUIInsetBounds(w,G,l,T)GuiService:SetGlobalGuiInset(w,G,l,T)end local w={}function T.FindPlayerHumanoid(G)local l=G and G.Character if l then local T=w[G]if T and T.Parent==l then return T else w[G]=nil for l,T in pairs(l:GetChildren())do if T:IsA("\072\117\109\097\110\111\105\100")then w[G]=T return T end end end end end end UIS.InputBegan:Connect(function(w)if w.KeyCode==Enum.KeyCode.LeftShift or w.KeyCode==Enum.KeyCode.RightShift then if Sprinting==false and Stamina.Value>StaminaReductionRate then(TS:Create(plr.Character.Humanoid,TweenInfo.new(3),{WalkSpeed=SprintSpeed})):Play()Sprinting=true repeat wait(StaminaReductionDelay)Stamina.Value=Stamina.Value-StaminaReductionRate until Sprinting==false;(TS:Create(plr.Character.Humanoid,TweenInfo.new(1.2),{WalkSpeed=OriginalWalkSpeed})):Play()end end end)UserInputService.InputEnded:connect(function(w)if w.KeyCode==Enum.KeyCode.LeftShift then if Sprinting==true then Sprinting=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.MouseButton1Down:Connect(function()if Sprinting==false and Stamina.Value>StaminaReductionRate then Border.Visible=false Sprinting=true;(TS:Create(plr.Character.Humanoid,TweenInfo.new(3),{WalkSpeed=SprintSpeed})):Play()repeat wait(StaminaReductionDelay)Stamina.Value=Stamina.Value-StaminaReductionRate until Sprinting==false;(TS:Create(plr.Character.Humanoid,TweenInfo.new(1.2),{WalkSpeed=OriginalWalkSpeed})):Play()elseif Sprinting==true and Stamina.Value<100 then Border.Visible=false Sprinting=false;(TS:Create(plr.Character.Humanoid,TweenInfo.new(1.2),{WalkSpeed=OriginalWalkSpeed})):Play()end end)Stamina.Changed:connect(function(e)if e<StaminaReductionRate then Sprinting=false end local h=script.Parent:WaitForChild("\070\114\097\109\101\095\066\097\114")local j=script.Parent.Frame_Bar:WaitForChild("\070\114\097\109\101\095\066\097\114\070\105\108\108")j:TweenSize(UDim2.new(e/100,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quart,.5,true)local C={[Vector3.new(w.r,w.g,w.b)]=.1,[Vector3.new(G.r,G.g,G.b)]=.5;[Vector3.new(l.r,l.g,l.b)]=.8}local M=.1 local I=w local Z=.8 local V=l local function f(w)if w<M then return I elseif w>Z then return V end local G=Vector3.new(0,0,0)local l=0 for T,e in pairs(C)do local h=w-e if h==0 then return Color3.new(T.x,T.y,T.z)else local w=1/(h*h)G=G+w*T l=l+w end end local T=G/l return Color3.new(T.x,T.y,T.z)end local z=Stamina.Value/100 if Stamina.Value==2 then Border.Visible=false end z=T.Clamp(0,1,z)local u=f(z)j.BackgroundColor3=u end)while true do wait(RegenerateDelay)if Sprinting==false and Stamina.Value<100 then Stamina.Value=Stamina.Value+RegenerateValue end end
--// Bar Colors //
local Stamina_Red_Color = Color3.new(255 / 255, 28 / 255, 0 / 255)
local Stamina_Yellow_Color = Color3.new(250 / 255, 235 / 255, 0)
local Stamina_Green_Color = Color3.new(27 / 255, 252 / 255, 107 / 255)

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

UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
		if (Sprinting == false) and (Stamina.Value > StaminaReductionRate) then
			TS:Create(plr.Character.Humanoid, TweenInfo.new(3), { WalkSpeed = SprintSpeed }):Play()
			Sprinting = true
			repeat
				wait(StaminaReductionDelay)
				Stamina.Value = Stamina.Value - StaminaReductionRate
			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 then
			Sprinting = 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.MouseButton1Down:Connect(function()
	if (Sprinting == false) and (Stamina.Value > StaminaReductionRate) then
		Border.Visible = false
		Sprinting = true
		TS:Create(plr.Character.Humanoid, TweenInfo.new(3), { WalkSpeed = SprintSpeed }):Play()
		repeat
			wait(StaminaReductionDelay)
			Stamina.Value = Stamina.Value - StaminaReductionRate
		until Sprinting == false
		TS:Create(plr.Character.Humanoid, TweenInfo.new(1.2), { WalkSpeed = OriginalWalkSpeed }):Play()
	elseif Sprinting == true and Stamina.Value < 100 then
		Border.Visible = 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
	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, 0.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 == 2 then
		Border.Visible = false
	end

	staminaPercent = Util.Clamp(0, 1, staminaPercent)
	local staminaColor = HealthbarColorTransferFunction(staminaPercent)
	Fill.BackgroundColor3 = staminaColor
end)

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