isRunning=false isExhuasted=false player=game.Players.LocalPlayer staminaGui.Parent=player.PlayerGui UserInputService.InputBegan:Connect(function(C)local h=game.Workspace:WaitForChild(player.Name)if C.KeyCode==Enum.KeyCode.LeftShift then if stamina>=minStaminaToRun then if isExhuasted==false then isRunning=true h.Humanoid.WalkSpeed=runSpeed RunService.RenderStepped:Connect(function()if isExhuasted==true then isRunning=false h.Humanoid.WalkSpeed=defaultWalkSpeed end end)else isRunning=false h.Humanoid.WalkSpeed=defaultWalkSpeed end end end end)UserInputService.InputEnded:Connect(function(C)local h=game.Workspace:WaitForChild(player.Name)if C.KeyCode==Enum.KeyCode.LeftShift then isRunning=false h.Humanoid.WalkSpeed=defaultWalkSpeed end end)RunService.RenderStepped:Connect(function()if stamina>0 then isExhuasted=false else isExhuasted=true isRunning=false end staminaGui.StaminaFrame.Bar.Size=UDim2.new(stamina/maxStamina,0,1,0)staminaGui.StaminaFrame.StaminaLabel.Text="\083\116\097\109\105\110\097\058 "..(stamina..("\047"..maxStamina))end)while wait(1)do if isRunning==true then stamina-=staminaPerSecond else if stamina<maxStamina then stamina+=staminaRegenPerSecond end end end
--]

isRunning = false --Is the character running?
isExhuasted = false --Is the character exhausted?

player = game.Players.LocalPlayer --The player

staminaGui.Parent = player.PlayerGui --Sets the stamina Gui's parent to the playerGui (therefore making it visible)

UserInputService.InputBegan:Connect(function(input)
	local character = game.Workspace:WaitForChild(player.Name)

	if input.KeyCode == Enum.KeyCode.LeftShift then
		if stamina >= minStaminaToRun then
			if isExhuasted == false then
				isRunning = true
				character.Humanoid.WalkSpeed = runSpeed

				RunService.RenderStepped:Connect(function()
					if isExhuasted == true then
						isRunning = false
						character.Humanoid.WalkSpeed = defaultWalkSpeed
					end
				end)
			else
				isRunning = false
				character.Humanoid.WalkSpeed = defaultWalkSpeed
			end
		end
	end
end)

UserInputService.InputEnded:Connect(function(input)
	local character = game.Workspace:WaitForChild(player.Name)

	if input.KeyCode == Enum.KeyCode.LeftShift then
		isRunning = false
		character.Humanoid.WalkSpeed = defaultWalkSpeed
	end
end)

RunService.RenderStepped:Connect(function()
	if stamina > 0 then
		isExhuasted = false
	else
		isExhuasted = true
		isRunning = false
	end

	staminaGui.StaminaFrame.Bar.Size = UDim2.new(stamina / maxStamina, 0, 1, 0)
	staminaGui.StaminaFrame.StaminaLabel.Text = "Stamina: " .. stamina .. "/" .. maxStamina
end)

while wait(1) do
	if isRunning == true then
		stamina -= staminaPerSecond
	else
		if stamina < maxStamina then
			stamina += staminaRegenPerSecond
		end
	end
end
