Stamina goes to 101 for some reason

i have this fully functioning stamina bar but whenever i test my game or play it live, the stamina goes up to 101 even though i never specified it to.

local bar = script.Parent

local stamina = 100

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local humanoid = char:WaitForChild("Humanoid")

local isJumping = false

local uis = game:GetService("UserInputService")


local jumpDebounceTime = 0.5 -- wait 1 second before they can jump again
local nextJump = 0 -- don't change this one, it's the time they can jump again
humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
	if stamina == 0 or nextJump > tick() then
		return
	end

	nextJump = tick() + jumpDebounceTime -- schedule next possible jump
	isJumping = true

	wait(1)

	if isJumping then
		humanoid.JumpPower = 50
		wait()
	end
end)


while wait() do

	if stamina == 0 then
		isJumping = false
		humanoid.JumpPower = 0
		wait(5)
		humanoid.JumpPower = 50
	end


	if isJumping then
		humanoid.JumpPower = 50
		stamina -= 15
		isJumping = false
		wait()
	else
		stamina += 1
		wait()
	end
	
	local staminatext = script.Parent.Parent.Stamina
	
	staminatext.Text = (math.floor(stamina).." / 100")

	stamina = math.clamp(stamina, 0, 100)

	bar:TweenSize(UDim2.new((1/100) * stamina, 0, 1 ,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 0.1)
end
1 Like

this is the reason right here…

3 Likes

oh then i should just add an if statement checking if its under 100

yep it worked! thank you for pointing that out

that works, I would just remove the stamina += 1 alltogether

but then the stamina doesnt regenerate

then make it regenerate? I dont know, didnt look through the whole script, just read through it and saw the problem

that stamina += 1 is what makes it regenerate there was just no check there to see if it was under 100 before it did

oh now i understand now yeah that stamina += 1 part of the code repeats whenever the player isn’t jumping so its not just running once