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
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,
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.
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
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)
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 This topic might help you solve the problem:
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.