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)
-- Variables -- local character = script.Parent local humanoid = character:WaitForChild("Humanoid") local isJumping = false local UserInputService = game:GetService("UserInputService") local DisablingJumpingTime = 5 -- Script -- humanoid.StateChanged:Connect(function(oldState, newState) if newState == Enum.HumanoidStateType.Jumping then if not isJumping then isJumping = true wait() -- dont know why, but this wait() fixes it humanoid.JumpPower = 0 -- Instead of disabling the jumping, you can change the JumpPower to 0 instead! end elseif newState == Enum.HumanoidStateType.Landed then if isJumping then isJumping = false wait(DisablingJumpingTime) humanoid.JumpPower = 50 end end end)