Double jump system doesnot work sometime

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)

Here

2 Likes

what that script is not even working

What i want to know is why sometime player is not double jumping

i think jumpRequest has a bug that makes it trigger 3 times in maybe not a second but even before the state function fires, i prefer using input service’s normal keycode and setting it to spacebar, there has been a lot of useless ROBLOX updates that cause some decented or something like that so you should add spaces between setting some values in boolvalues

1 Like

Ok i will try that . but What space . is that “_” .

What the i am amaze this work . Roblox should really fix those stupid bugs . Now i also know why my slide system was not working