Don't want BindAction Enum.UserInputType.Touch to be call when move on phone

As the title said, this is what the code looks like

ContextActionService:BindAction("BasicAttack", BasicAttack, false, Enum.UserInputType.Touch)

The function “BasicAttack” will be called every time a player touch or release the screen. The problem is it also run the function when touching the controller to move on mobile, which I don’t want that to happen. Any ways to prevent this? Thanks in advance

Swap the third argument from false to true and remove the input type enumeration item.

When BindAction’s third argument is true it creates a button for touchscreen users for the bound action.

1 Like

Thanks for the reply. But the user will only have to tap on that specific button? I want the player to be able to tap anywhere on the screen, except I don’t want it to run when the player taps the move controller, I knew this sound kinda tedious and I saw many games also have this problem. So, hopefully, there is a better way to solve it.

If you want it so they can tap anywhere on the screen then use userinputservice.inputbegan and do if input.UserInputType == Enum.UserInputType.TouchTap,

Yes, that’s what my code from the start do

ContextActionService:BindAction("BasicAttack", BasicAttack, false, Enum.UserInputType.Touch)

So, now it came back to my main problem. “Don’t want it to run when I move on phone”. Even I use your method, the function still run when I move the controller on phone (which I don’t want it)

TouchTap not Touch, Touch will only signal when you release your finger, What are you referring to by “Controller”? Are you referring to the mobile joysticks or an actual physical controller device.

Yes, the controller means mobile joystick

userinputservice has 2 parameters : (input,gameProcessed) on the very first line put it gameProcessed then return end

still it doesn’t work when I tested on studio. Wait again imma test on the real phone

Nope it not work, here’s my code

local UIS = game:GetService("UserInputService")
local function BasicAttackMobile(input, isGameProcess)
	if input.UserInputType == Enum.UserInputType.Touch and not isGameProcess then
		// Do attack
	end
end
UIS.InputBegan:Connect(BasicAttackMobile)

You can try it yourself, when I move the joystick on mobile, it still run the function

Are you sure Touch is what you want? And not Touch tap?

cuz, idk why. But TouchTap seems to not working

I believe you need to check the state of the input. InputObjects have a begin state, end state, and change state. If you want the start of the touch, you should check if the input object is in the begin state.

Edit: Don’t need to check the input state for UserInputService since the events already are separated by input state.

Ex:

local UIS = game:GetService("UserInputService")
local function BasicAttackMobile(input, isGameProcess)
	if (input.UserInputState == Enum.UserInputState.Begin) and (input.UserInputType == Enum.UserInputType.Touch) and (not isGameProcess) then
		-- Do attack here
	end
end
UIS.InputBegan:Connect(BasicAttackMobile)

API:
https://developer.roblox.com/en-us/api-reference/property/InputObject/UserInputState
https://developer.roblox.com/en-us/api-reference/enum/UserInputState

Edit:

Oh, I misunderstood what you were asking. I thought that isGameProcessed worked for the joy stick, I guess not though. That’s hard to solve … I’m not sure.

ofc egomoose has a solution for everything :smile: This topic might help you solve the problem:

1 Like

Still it doesn’t solve my problem. When I move the joystick on the phone it still run the function. I don’t want it to run when I tap the joystick on mobile, I only want it to run when tap anywhere else.

1 Like

You only need to check state for contextactionservice, .InputBegan is the same as Enum UserInputState Began, vice versa.InputEnded

1 Like

Whoops, my bad. I saw context action service in the original post and then copied the code without thinking about that.

1 Like

Yes, thanks a lot. This post has an ideal solution.

1 Like