Buggy double jump replacement?

here is my double jump script:

local Character = script.Parent
local CanDouble = false
local OnGround = true
local Humanoid = Character:WaitForChild(“Humanoid”)
local UIS = game:GetService(“UserInputService”)

Humanoid.StateChanged:Connect(function(old,new)
if new == Enum.HumanoidStateType.Freefall and OnGround then
if not CanDouble then
CanDouble = true
OnGround = false
end
else if Humanoid.FloorMaterial ~= Enum.Material.Air then
OnGround = true
CanDouble = false
end
end
end)

local function Jump()
if CanDouble and Humanoid.FloorMaterial == Air then
CanDouble = false
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end

UIS.JumpRequest:Connect(Jump)

For some reason, when I double jump it sometimes does it too quickly without my control. Can someone help this please?