Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to disable the space bar temporarily after landing?

I want to add a cooldown to the space bar that disables it temporarily after the player lands. I'm not trying to add a cooldown to jumping but to the space bar. I don't know where I went wrong, any help?

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

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

local recentJumpPower = nil


humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Jumping then
		recentJumpPower = humanoid.JumpPower

		isJumping = true
	elseif old == Enum.HumanoidStateType.Jumping and isJumping then
		humanoid.JumpPower = 0
		isJumping = false
		wait(DisablingJumpingTime)
		humanoid.JumpPower = recentJumpPower
		isJumping = true
	end
end)

I hate games that do this though

This discussion is preserved as it was. New answers, comments, and votes are closed.