How to detect double inputs for jumping?

Ok then the script I’ve re-posted should be fine… Have you tested the newest re-post?

The code is fine for double-jumping, but not the type of “detection” I needed. I’m finishing up my iteration soon so I’ll lyk how that will go.

Hello everybody, thanks for all the help! I created a rough draft of the functionality I wanted. While this works, the code is currently not optimized the best and is not the cleanest. If you ever need this type of functionality, please clean up the code.

Thanks to @GuinPeng for giving me the bad news that I had to use UserInputService


local lastJumpTime = os.clock()
Humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping then
		hasJumped = true
		lastJumpTime = os.clock() --Record the last jump time for climb window
	elseif newState == Enum.HumanoidStateType.Landed then
		hasJumped = false
	end
end)

local IsTouchEnabled = UserInputService.TouchEnabled
local TestConn = nil
UserInputService.LastInputTypeChanged:Connect(function()
	IsTouchEnabled = UserInputService.TouchEnabled
	
	if not IsTouchEnabled then
		if TestConn then
			TestConn:Disconnect()
			TestConn = nil
		end
		return
	end
		
	if TestConn then
		return
	end
		
    local JumpButton: ImageButton = PlayerGui.TouchGui.TouchControlFrame.JumpButton
		
    TestConn = JumpButton.InputBegan:Connect(function()
		if not hasJumped then return end
		if os.clock() - lastJumpTime < ALLOWED_MANTLE_THRESHOLD_TIME then return end
		
        ...
	end)
end)
	
UserInputService.InputBegan:Connect(function(Input, GPE)
	if GPE and not UserInputService.GamepadEnabled then return end --For some reason, console cannot detect the A button press when checking GPE
	if not hasJumped then return end
	if Input.KeyCode ~= TestInputs[Input.KeyCode] then return end
	if os.clock() - lastJumpTime < ALLOWED_MANTLE_THRESHOLD_TIME then return end
		
    ...
end)
2 Likes

I hope it worked for you as intended.

1 Like