Problem with detecting jump button on mobile being pressed

So, I’m trying to create a jumping beat block for an obby where when you press space or jump and it’ll activate the next block. And also you can switch them while you’re in mid air.

Here’s an example video of it working properly:

Yes, I have made one working version that “only” works on PC, not mobile. I’m trying to make it work on mobile as well but I haven’t found any solution that doesn’t require a “jank” or hacky way to do it.

This was the code that it was using:

Code
uis.InputBegan:Connect(function(inp, gameInput)
		
		if gameInput or pointIsNearBlocks() ~= true or not (inp.KeyCode == Enum.KeyCode.Space or hum ~= nil and hum:GetState() == Enum.HumanoidStateType.Freefall) then
			return
		end
		
		print("passed")

		ding()

		for _, p in parts do
			if p.Name == tostring(beat) then
				setActive(p, false)
			end
		end

		beat += 1
		if beat > maximum then
			beat = 1
		end

		for _,v in ipairs(parts) do
			if v.Name == tostring(beat) then
				setActive(v, true)
			end
		end
		
	end)

Here’s the video that doesn’t work properly:

In the video, That’s what happened when I tried UserInputService.JumpRequest and Humanoid.Jumping events. It fires way more than I’d like.

Solutions I have tried:

  1. Using UserInputService.JumpRequest event: It fires too much, if I add a debounce to it, it’ll have a really weird timing.

  2. Using Humanoid.Jumping event: It’s just the same as JumpRequest. I’ve tried using the active parameter and it does work, but it won’t switch when you try clicking the jump button while in mid air, so this doesn’t do it for me.

  3. Using Humanoid.StateChanged event: Tried it and it’s basically the same as Humanoid.Jumping.

  4. Using Humanoid:GetState function: This was my first “solution”, and tried it within UserInputService.InputBegan event. But I found out that it doesn’t really register Enum.HumanoidStateType.Jumping, most of the time it’ll register as Enum.HumanoidStateType.FreeFall or Enum.HumanoidStateType.Running even though you’re jumping. I did try changing the parameters to these enums but still doesn’t work.

  5. Using ContextActionService:BindAction function: This was my last resort or solution that I thought would fix it, and it did it, but for some reason it only works for one of the beat blocks, and the others doesn’t work. And yes, I’ve put an Enum.ContextActionResult.Pass return and I have also randomized the actionName. Also I haven’t used CAS that much so I might be missing something here.

So right now I’m kind of at a loss here. Most solutions that I tried have problems like; it fires way too much or often, using the active parameter on Humanoid.Jumping event doesn’t work because I want it to be able to switch it when you’re in mid air aswell, thought ContextActionService:BindAction would do it, but for some reason it’ll only register one function only even though I’ve thrown a Pass enum.

I know I could just use a TextButton or ImageButton to detect it but I want to know, is there any other way to detect it rather involving some hacky methods? Thank you.
(Sorry if this topic or post kind of confusing, not rly good at explaining things. And also this is my first post on scripting support, so yeah lol)

Figured out a way, I modify the TouchJump module inside the ControlModule of PlayerModule. Made the jump button to be assigned to a global variable (ik that its not a great way to just assign it, but im too lazy lol) so I can access the InputBegan event.

I only put a line inside the TouchJump:Create function: _G.buttonJumpThing = jumpButton

Probably if only want to access the event only then I think it’s better to assign it as only an event.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.