I want to make a double jump system that only gives you two jumps before a cooldown. You can either Jump and Double Jump or just Spam Jump. Problem is, I scripted the playerjump script to only work with one jump. How do I make it so that when two jumps happens, the cooldown starts?
function playerJump(input: InputObject, clickCount, jumpButton)
if Humanoid.Health == 0 then return end
if not isJumping then
isJumping = true
createCooldown(jumpButton, JUMP_WAIT_TIME, Color3.fromRGB(255, 55, 62), 0.5, true)
local oldJumpPower = Humanoid.JumpPower
Humanoid.JumpPower = 100
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
Humanoid.JumpPower = oldJumpPower
jumps += 1 -- incrementing?
task.wait(JUMP_WAIT_TIME) -- cooldown should only start when there are two jumps..
if jumps == 2 then -- none of this works but I tried to get an idea
jumps = 0
end
isJumping = false
end
end
i guess this should works?
okey i just added the boolean if its come true make it false after 2 sec and while 2 sec ( while boolean = false) dont make player do 2 jumps (:
howMuchCanPlayerJump = 2
cooldown = 2
-- you can change these but there is no mind so (: idk
limitJumps = 2
lock_double_jump = false
function playerJump(input: InputObject, clickCount, jumpButton)
if Humanoid.Health == 0 then return end
if not isJumping then
isJumping = true
createCooldown(jumpButton, JUMP_WAIT_TIME, Color3.fromRGB(255, 55, 62), 0.5, true)
local oldJumpPower = Humanoid.JumpPower
Humanoid.JumpPower = 100
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
Humanoid.JumpPower = oldJumpPower
jumps += 1 -- incrementing?
task.wait(JUMP_WAIT_TIME)
if not lock_double_jump then
limitJumps = howMuchCanPlayerJump
else
limitJumps = 1
end
if jumps == limitJumps then
jumps = 0
end
lock_double_jump = true
isJumping = false
end
end
while wait() do
if lock_double_jump then
wait(cooldown)
lock_double_jump = false
end
end
To implement a double jump system with a cooldown you can modify your playerJump function to track the number of jumps and start a cooldown after the second jump.
Here’s how you can do it:
local isJumping = false
local jumps = 0
local JUMP_WAIT_TIME = 2 -- Adjust the jump wait time as needed
function playerJump(input: InputObject, clickCount, jumpButton)
if Humanoid.Health == 0 then return end
print("Jump triggered")
if not isJumping then
isJumping = true
local oldJumpPower = Humanoid.JumpPower
Humanoid.JumpPower = 100
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
Humanoid.JumpPower = oldJumpPower
jumps = jumps + 1
print("Total jumps:", jumps)
if jumps == 2 then
print("Starting jump cooldown")
createCooldown(jumpButton, JUMP_WAIT_TIME, Color3.fromRGB(255, 55, 62), 0.5, true)
task.wait(JUMP_WAIT_TIME)
jumps = 0 -- Reset jumps after cooldown
print("Jump cooldown ended")
end
isJumping = false
end
end