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
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
local Debounce = false
function Jump()
if not Debounce then
Debounce = true
--jump code
wait(2)
Debounce = false
end
end
I did not write the entire script, I only wrote the cool down portion.
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
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