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)
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.
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!