I want to prevent a player from just holding their space bar to jump, and so have a cooldown. However, I want to add controller support, and am getting problems where A won’t always jump.
I can jump once, and then I’m unable to jump ever again
Please note, this code WORKS with PC. Just not on controller
--// Request made to jump
local function JumpRequest()
if Humanoid.FloorMaterial ~= Enum.Material.Air then return end -- Not in the air
CanJump = false
Humanoid.JumpPower = 0
delay(JUMP_COOLDOWN, function()
CanJump = true
end)
end
--// Input began
local function InputBegan(input, GPE)
if GPE then return end
if Humanoid.Health <= 0 then return end -- Dead
if input.KeyCode ~= Enum.KeyCode.Space and input.KeyCode ~= Enum.KeyCode.ButtonA then return end -- Not jump key
if not CanJump then return end
CanJump = false
Humanoid.JumpPower = JUMP_POWER
Humanoid.Jump = true
end
NewMaid:GiveTask(UserInputService.JumpRequest:Connect(JumpRequest))
NewMaid:GiveTask(UserInputService.InputBegan:Connect(InputBegan))