How do I disable jumping when stamina is below 20?

i am extremely unable to disable jumping whenever stamina is below 20.

It doesn’t work, infact it also breaks the jump cooldown, and I seriously have no clue how to make it work.

local humanoid = script.Parent:WaitForChild("Humanoid")

local Stamina = game:GetService("Players").LocalPlayer:WaitForChild("Stamina")


Stamina.Changed:Connect(function()
	if Stamina.Value < 20 then
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)		
	else
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	end
end)


-- i ripped this function from one of my previous posts, to be honest i don't really know how it works but it works :D
humanoid.StateChanged:Connect(function(old,new)	
	if new == Enum.HumanoidStateType.Jumping then

		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,false)
		task.wait(1)
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,true)

	end
end)

set humanoid.JumpPower = 0 to remove jump
set it to the default value to give the jump back

that won’t fix anything

the jump cooldown works, but it breaks after the first jump because of the Changed event

why does it not work?

stamina.Changed fires when the stamina changes

when you set the jumping state to false when the stamina is below 20, it disables their jump if they are jumping only at that moment

setting the jumppower disables the jump until its changed again

so setting the jump power disables the jump when stamina is below 20 and re enables it above 20

if JumpPower would work then i wouldn’t be using the yoinked code from my previous post (humanoid.StateChanged:Connect(function(old,new))

There’s some weird properties you have to tick and untick and I just can’t be bothered to do those, so i’m using the same method

i am no code expert but i’m pretty sure it just sets jump to true whenever stamina changes, which breaks the cooldown ← mindbreaking discovery i know

i’m trying to fix that, without having to tinker with properties

I know this might be Necro-posting but I am having a similar problem with my script.

When you jump the second time,
-(After recovering your stamina above the minimum stamina for jumping)-
does it not do a proper normal jump?

For my case, (100 max stamina)
Player jumps (-50 stamina), when stamina regenerate and stamina > 49.
Logically, the player should be able to jump again.
My player did jump but not a full jump, the player is somehow glued to the floor.

To make the player not able to jump when stamina < 49, I used “humanoid.JumpHeight = 0”.
and when stamina > 49, it will be set to default value.

To be honest, I feel like it could be just Roblox Engine limitation.

*Note: after re-reading the post again, I realised I have a different problem lol.
I did managed to disable jump but by changing properties, i.e. jump power/height.
Just that by modifying that, I believe there is a delay in the 2nd jump when using more than minimum leftover stamina.

04/01/2025 - I fixed my issue. It had something to do with the humanoid state. If you need the script, feel free to DM me.

Here’s a skeleton @notsad2

local stamina = script:WaitForChild("Stamina")  
local tired
local jumping
local plrs = game:GetService("Players")
local localplayer = plrs.LocalPlayer
local Humanoid = localplayer.Character:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")


local function checkTiredness()
	if stamina.Value < 20 then
		print("You are tired")
		tired = true
	else
		print("You are not tired")
		tired = false
	end
end


local function ifTired()
	if tired then
		print("tired")
		jumping = false
	else
		print("not tired")
		jumping = true
	end
end


local function ifJump()
	if jumping then
		print("Jumping") 
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	else
		print("Not Jumping")
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	end
end


local function constantChecks()
	RunService.Heartbeat:Connect(function()
		checkTiredness()
		ifTired()
		ifJump()
	end)
end


jumping = false  
constantChecks()  

You can set stamina to anything, here I’ve set it to a Numbervalue under the script.
hope this helps!