--]


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

