I want to add a denounce to the space bar when the player jumps, and disable it temporarily. The problem is, I don't know how to do this. Here is my failed attempt.
local character = script.Parent
local JUMP_DEBOUNCE = 5
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
if not isJumping then
isJumping = true
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping and Enum.KeyCode.Space, false)
end
elseif newState == Enum.HumanoidStateType.Landed then
if isJumping then
isJumping = false
wait(JUMP_DEBOUNCE)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)

4 comments
This way is more straightforward and easier. If this helped you, please consider marking this an answer so people will know!
If this didn't work, try putting this on StarterPlayer > StarterCharacterScripts and putting this as an LocalScript. Thanks for reading!
I appreciate your help but how can this be done with the space bar?
Oh, you actually can, just replace the humanoid.JumpPower = 0 to humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping and Enum.KeyCode.Space, false). I am not really sure since I do not understand a lot of HumanoidStateType. So humanoid jump power is the best way for me!