I made double jump system but sometime double jump is not working . Help me please
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local uis = game:GetService("UserInputService")
local numjumps = 0
local canjump = false
local maxjump = 2
local function onstatechanged(oldstate,newstate)
if newstate == Enum.HumanoidStateType.Jumping then
canjump=false
numjumps +=1
else if newstate == Enum.HumanoidStateType.Landed then
numjumps = 0
canjump=false
else if newstate == Enum.HumanoidStateType.Freefall then
wait(0.2)
canjump=true
end
end
end
end
local function doublejump()
if canjump and numjumps < maxjump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
humanoid.StateChanged:Connect(onstatechanged)
uis.JumpRequest:Connect(doublejump)