Ad
Log in to vote
0

How to disable the space bar temporarily after jumping?

Asked by 7 days ago

I want to add a denounce to the space bar after it is pressed and disable it temporarily. The problem is, I don't know how to do this. Here is my failed attempt.

UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local isJumping = false
local UserInputService = game:GetService("UserInputService")
local DisablingJumpingTime = 5


UserInputService.InputBegan:Connect(function(input,gameProccesedEvent)
    if input.KeyCode == Enum.KeyCode.Space then 
        if not isJumping then
            isJumping = true
            wait() 
            input.Keycode.Space = false 
        end
    elseif input == Enum.HumanoidStateType.Landed then
        if isJumping then
            isJumping = false
            wait(DisablingJumpingTime)
            input.Keycode.Space = true
        end
    end
end)

1 answer

Log in to vote
2
Answered by 7 days ago
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local UserInputService = game:GetService("UserInputService")
local DisablingJumpingTime = 5

local debounce=false
UserInputService.InputBegan:Connect(function(input)
    if debounce then return end
    if input.KeyCode == Enum.KeyCode.Space then
        debounce=true
        wait()
        humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,false)
        wait(DisablingJumpingTime)
        debounce=false
        humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,true)
    end
end)
Ad

Answer this question