I’m currently trying to create a jump fatigue system. I have the section in place where it lowers the player’s jump power every time they jump, but I’m now stuck. How would I detect if the player has jumped in the last second? I need this because if they didn’t, the jump power will be reset to normal. In a way, kinda like Fortnite’s jump fatigue system.
Code that updates jump power:
local function UpdateJumpPower()
if JumpAmt == 3 then
Hum.JumpPower = Jump3Power
elseif JumpAmt == 4 then
Hum.JumpPower = Jump4Power
elseif JumpAmt >= 5 then
Hum.JumpPower = Jump5Power
Hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
wait(.5)
Hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
Hum.StateChanged:Connect(function(OldState, NewState)
if NewState == Enum.HumanoidStateType.Jumping then
JumpAmt += 1
UpdateJumpPower()
end
end)
As you can see, I remove the player’s jump power, but I need a way to detect when they haven’t jumped for a second, so I can give it back.
You can write your topic however you want, but you need to answer these questions:
You could set a variable to os.time when like y’know the fatigue needs to start. Then after whatever interval just subtract the current os.time value from the one you assigned to the variable.
Hey, what is this script under? The workspace? StarterCharacter scripts? We need that kind of information so we can find out how to keep your script working without changing the parent and ruining other scripts that may rely on the code you have here.
This works well, however, I run into an issue. The first few jumps after the pause are very static, almost as if the jumpower is constantly changing. Why would that be?
local function UpdateJumpPower()
if JumpAmt == 0 then
Hum.JumpPower = 50
elseif JumpAmt == 3 then
Hum.JumpPower = Jump3Power
elseif JumpAmt == 4 then
Hum.JumpPower = Jump4Power
elseif JumpAmt >= 5 then
Hum.JumpPower = Jump5Power
Hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
wait(.5)
Hum:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
Hum.StateChanged:Connect(function(OldState, NewState)
if NewState == Enum.HumanoidStateType.Jumping then
if os.clock() - LastJumpedTime >= 1 then
JumpAmt = 0
end
print(JumpAmt)
LastJumpedTime = os.clock()
JumpAmt += 1
UpdateJumpPower()
end
end)
local Hum = script.Parent -- Keep your variable for the humanoid.
Hum.Jumping:Connect(function(Jumping)
if Jumping == true then
Hum.JumpPower = Hum.JumpPower - 1
end
end)
Try changing your function to this one. Be sure to include the “Jumping” boolean.
I belive its because it only resets after it receives the jump request, making the first jump at the 5th jump power. Is there a way I could stop that first jump from happening and then make the player jump via script?
Here, I created this for you with the information that I’ve gathered. Try and see if it works.
local Hum = script.Parent -- Change this to whatever you need
local Resting = false -- Remove this is need be.
local function RegenStamina(Stamina, Jumping, MaxJumpAmt)
while true do
if Jumping == false and Stamina ~= MaxJumpAmt then
Stamina = Stamina + 1
task.wait(1)
elseif Jumping == true or Stamina == MaxJumpAmt then
break
end
end
end
local function UpdateJumpPower(Humanoid, Jumping)
local MaxJumpAmt = Humanoid.JumpPower
local JumpAmt = Humanoid.JumpPower
if Jumping == true then
JumpAmt = JumpAmt - 1 -- Change this to whatever you need.
elseif Jumping == false and Resting == false --[[Remove this if you removed the "Resting" boolean.]] then
Resting = true -- Remove this if you removed the "Resting" boolean.
task.wait(3) -- Change this to whatever. Remove this if you removed the "Resting" boolean.
RegenStamina(JumpAmt, Jumping, MaxJumpAmt)
Resting = false -- Remove this as well if you removed the "Resting" boolean.
end
end
Hum.Jumping:Connect(function(Jumping)
UpdateJumpPower(Hum, Jumping)
end)