How can i implement a debounce without breaking this script

ive tried for hours today to implement a debounce but every time i do, it allows the player to jump even if stamina hits 0. any help??

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")


humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
	if stamina == 0 then
		return
	end

	isJumping = true

	wait(1)

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


while wait() do

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


	if isJumping then
		humanoid.JumpPower = 50
		stamina -= 5
		isJumping = false
		wait()
	else
		stamina += 0.75
		wait()
	end

	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

instead of property change why not just use UIS to check if they pressed space?

I haven’t tested this but I am fairly certain that this will signal fires slightly AFTER the player actually jumps

humanoid:GetPropertyChangedSignal(“Jump”):Connect(function()

because i want the game to be mobile compatible, and this is the best way that i know of that can work for both

make an if statement for each type of input you want

should i just do jumprequest instead

For the record, it doesn’t matter whether you use JumpRequest, KeyCode.SpaceBar, or GetPropertyChangedSignal, your issue lies within the function itself.

whats the issue in my function? ive spent hours trying to fix this

I don’t know, I haven’t looked at it yet. I’m just responding to @Nogalo.

honestly there are a number of issues with the script

first off, your stamina is a value inside the script not a numbervalue stored in a folder inside Player instance
second, you are doing it all inside a local script, meaning i could just edit the script and set my stamina to 99999999999
thirdly you are relying on property signal change

but if i try to edit the stamina through the script, it just goes back to 100

that’s because you are editing it from a local script

this localscript is the only place my stamina is stored

Exactly my point. How will other scripts interact with it? This is why numbervalues exist. You store the value there so that all other scripts can know how much stamina a player has

but i dont have a need for other scripts to access that value since everything is already in that script

either way it’s a bad idea to keep it in a local script. You should be doing this in a server script. For which you would then need a number value to communicate between local and server script

its still not the issue im having tho i can change that later

i changed it to jumprequest and same issue

what kind of script is this (local or server)

the code is all in a local script

where is the local script located in the explorer