Hello! How can you make it so that you only jump once until you release the jump button and at the same time have a cool down? I have no idea how that would work
How do you make a jump cooldown/delay?
3 answers
local us = game:GetService("UserInputService")
local canJump = true
us.JumpRequest:Connect(function()
if canJump then
canJump = false game.Players.LocalPlayer.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
wait(2)
canJump = true
game.Players.LocalPlayer.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end)
UserInputService has an event which fires each tick when the spacebar is held down, called JumpRequest. Humanoids have a function which allows you to toggle certain controls, like jumping, climbing, walking, running, etc. Setting these to false disables that certain control. Using these, you can make a debounce variable as shown above.
Use the user input service to listen for the space key to be pressed and when the key is pressed change the jump power to however high you want it, wait a few seconds then change the jump power to zero. Don't forget to use debounce, debounce is the key to make the cool down.
3 comments
So that means I have to change the default jump power to 0, and then to 50 when the spacebar is pressed?
Yes. Try that.
When i tried that, my character didn't jump.
You can make use of debounce. For example, I used the following script for my punch animation. Along with Debounce if you add a wait time after each jump like I have done in my script (for punch) then I think you are good to go.
local Player = game.Players.LocalPlayer
local Character = Player.Character or script.Parent
local Humanoid = Character.Humanoid
local UserInputService = game:GetService("UserInputService")
local AnimationID = "rbxassetid://4860770751"
local Debounce = true
local key = 'F'
UserInputService.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode[key]and Debounce == true then
Debounce = false
local Animation = Instance.new("Animation")
Animation.AnimationId = AnimationID
local LoadAnimation = Humanoid:LoadAnimation(Animation)
LoadAnimation:Play()
wait(.5)
Animation:Destroy()
Debounce = true
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
How would you make the character jump only one time until the spacebar is released?
You would use us.InputEnded:Connect(function(key) and check if the key was spacebar.