Can someone help me make a JumpCooldown script every 2 seconds?

Hey, I was wondering if someone could help me make a JumpCooldown script so every 2 seconds I am able to jump, I have no idea how to make it and it is pretty essential for the game I am making.

Thanks :slight_smile:

local Debounce = false

function Jump()
    if not Debounce then
        Debounce = true
        --jump code

        wait(2)
        Debounce = false
    end
end
1 Like

I did not write the entire script, I only wrote the cool down portion.

3 Likes

This should be very helpful for you. Use in conjunction with debounce (as KeysOfFate described) in order to stop the character from being able to jump!

– sorry, got the wrong link, it’s actually setstateenabled :laughing:

1 Like
local ContextService = game:GetService("ContextActionService")
local torso = ... -- set this equal to the player's torso

local groundRayParams = RaycastParams.new()
groundRayParams.FilterDescendantsInstances = ... -- set this to the Player.Character

local function isGrounded()
  local rayResult = workspace:Raycast(
    torso.Position,
    - torso.CFrame.UpVector * 4,
    self.groundRayParams
  )
  
  if rayResult then
    return true
  else
    return false
  end
end

local function bindJumpContext()
  ContextService:BindAction(
    "JumpControllerContext",
      function()
       if isGrounded() then
          ... -- apply the jump
         ContextService:UnbindAction("JumpControllerContext")
         wait(2) -- two second cooldown
         bindJumpContext()
       end
    end,
    false,
    Enum.KeyCode.Space
  )
end