What is the equivalent of MouseClickButton1 for mobile?

Hello!
I made a function that basically does

function myFunction()
    print("Hello World!")
end

-- Here is supposed to be a line for PC Users using the UserInputService.
script.Parent.MouseButton1Click:Connect(myFunction)

That function can also be called by another line that uses UserInputService for PC users.
Problem: The button won’t work on mobile. It does nothing.

How to fix this?
Thanks!
- Meaxis

2 Likes

I am stupid. Used the wrong RemoteEvent, I am really sorry!
(that means: mousebutton1click works on mobile)

7 Likes

Use .Activated:Connect for it to work with mobile and Xbox.

Please search first before asking. Your question could’ve been answered very easily by just reading the TextButton documentation page. The equivalent to MouseButton1Click for mobile is TouchTap.

local function myFunction()
    print("Hello World!")
end

script.Parent.MouseButton1Click:Connect(myFunction)
script.Parent.TouchTap:Connect(myFunction)
3 Likes

Actually MouseButton1Click works on mobile.

1 Like

I’m answering your original question, “What is the equivalent of MouseButton1Click for mobile?”. The equivalent is TouchTap. This answers the question objectively.

Canonically, you aren’t supposed to be using mouse events for mobile since mobile devices don’t have a soft/hardware mouse. If it works though and you don’t care about canonical programming or conforming to standard, then by all means. You really shouldn’t use mouse items for mobile though, it’s bad practice.

The point of my post is informing you that you should either search first or attempt to debug your code, as per the category guidelines. It doesn’t seem like you did either since your question could easily be answered by searching and you later found the problem to be a simple code mistake.

2 Likes
  1. Okay, I’ll fix my code to meet the standards.
  2. Sorry for disrespecting the category guidelines.
1 Like

Oh, no no, that’s fine. You don’t have to update your code; that’s just a suggestion from myself. People like myself tend to encourage proper practice when replying to DevForum requests and this is one of them.

I don’t encourage using mouse events for mobile, but I’m just saying. In this case, as mobile input is also registered as a click for GuiObjects, it’s fine. Just be wary down the line when working with mobile. There are cases where you don’t have a choice between using mouse or mobile events or it might cause you problems that you could easily avoid.

You can also consider it for the sake of code organisation, neatness and knowing what you’re working with. I tend to separate my input handlers by device or input type so I know explicitly what I’m working with. For example, if I just have a click function, then I get lost in trying to find where I handle mobile input. If I explicitly have segments for mobile, then I can view that piece and say “oh, that’s where my mobile input controls are, I can change the behaviour for mobile now”.


As for the category guidelines, just be more mindful of them in the future. You should always try and see if you’re able to resolve your problems first by searching for similar problems on the DevForum or via the API reference on the Developer Hub. You can also review your own code and debug it with the various tools available - even just printing is good enough for Roblox.

If you’ve tried things out and you can’t resolve the problem, posting here would be fine.

3 Likes

Thanks for the long answer, I’ll still update my code cause I have one GUI for PC (Press E to interact) and one for mobile (Tap here to interact), better update my code to fit the standards since it’s for mobile-only.

For the category guidelines part, I tried to avoid disrespecting them but didn’t look at the right place. I looked at MouseButton1Click’s page instead of looking at TextButton’s one. If I did that error, it’s because I had for some reason two RemoteEvents, one called “RunScript” and one called “ExecuteScript”, even though the “ExecuteScript” had no point in existing (wasn’t used anywhere in my code), I had pointed the script to listen to ExecuteScript and the LocalScript to fire at RunScript, and I didn’t notice that because the names were “similar” and I have a bad habit of asking DevForum right when I have a question and not looking up that much first. I am trying to fix that bad habit, but it isn’t that easy, especially since how annoying it is to search between answers that have almost the same topic than the one you’re looking for, the answers that are outdated, the toolbox items (I don’t really like using toolbox items).

Anyways, thanks for the advice, and sorry for my mistake of not following the category guidelines.

1 Like