Assigning jump key on console really buggy

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 :confused:

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))

Have you tried putting the JumpRequest code at the start of the InputBegan code, as in:

-A is pressed
-Checks if player can jump
-If they can, set their jump power and jump them

Pressing A returns a GPE, however I need the if GPE then return end, as you’d jump when typing in chat