Does MouseButton1Down supports mobile?

Hi Guys, so I wrote a LocalScript. I tried and tested it using my mobile and it didn’t worked. It was about clicking a button. I researched a bit and found that MouseButton1Down doesn’t really work for mobile. Although in all my ScreenGui’s, I used this only. But it’s not working for a SurfaceGui button. On PC, it works fine but it doesn’t on mobile. So does MouseButton1Down don’t support mobile?

yes it works on mobile devices

local button = script.Parent

local function leftMouseButtonUp(x, y)

print("Left mouse up at", x, y)

end

local function leftMouseButtonDown(x, y)

print("Left mouse down at", x, y)

end

button.MouseButton1Up:Connect(leftMouseButtonUp)

button.MouseButton1Down:Connect(leftMouseButtonDown)

Why wouldn’t you just use UserInputType.Touch?

this event is for a specific button

Although, this isn’t working for me for some reason. Even my code is fine, I’ve even posted that many times here. But MouseButton1Click or .Activated works perfectly.

Code using MouseButton1Down -

local MPS = game:GetService("MarketplaceService")

game.ReplicatedStorage.AddButton.OnClientEvent:Connect(function()
	for i, button in pairs(workspace:GetDescendants()) do
		if button:IsA("TextButton") then
			print(button.Name)
			button.MouseButton1Down:Connect(function()
				print("Clicked")
				MPS:PromptPurchase(game.Players.LocalPlayer, button:GetAttribute("Id"))
			end)
		end
	end
end)


workspace.DescendantAdded:Connect(function(des)
	if des:IsA("TextButton") then
		print(des.Name)
		des.MouseButton1Down:Connect(function()
			print("Clicked")
			MPS:PromptPurchase(game.Players.LocalPlayer, des:GetAttribute("Id"))
		end)
	end
end)

Is there any reason you need to use button.MouseButton1Down over button.Activated?

TextButton.Activated takes into account the different possible types of input for the gui

Are you trying it on a real smartphone or in a studio in imitation of a smartphone?

I believe MouseButton1Down or Click was used over Activated for a while due to it being unreliable. Sometimes Activated would trigger and other times it would not. For this reason, all of my UI code has not used activated. I am unsure whether it is still unreliable, but this is a practice that I have kept because of it being unreliable.

Apologies if this seems poorly written, I was writing this on my phone.

I have never heard this before, do you know or remember where i can read more into this?

Just found this small post about someone having that issue. You will probably be able to find more of them. TextButton.Activated not working as intended

2 Likes

Well, I have been using .Activated more than .MouseButton1Click, and I have never ran into an issue with it, Activated also has Arguments you can use unlike MouseButton1Click (as far as im aware)

No reason. But asking that does that works?

I don’t see a reason why it shouldn’t

It doesn’t work though. You can check my code I provided above. If there’s something wrong, please let me know.

I don’t think the issue is actually the .MouseButton1Down event or the .Activated one, I’m more concerned about as to why you’re looking for textbuttons in workspace descendants?

are the textbuttons part of a workspace instance? like a surfacegui on a part?

If this is a localscript, and the textbuttons are part of ScreenGui objects, perhaps you should be running the loop on game.Players.LocalPlayer.PlayerGui instead.

Also make sure the localscript is parented somewhere in the PlayerGui/StarterGui folder.

Edit: Had to add that your code would indicate that your textbuttons aren’t following these parameters from the documentation:

If the button doesn’t work as expected, check the following:

  • Make sure you used a client-side LocalScript, not a server-side Script.

  • Ensure that the LocalScript is a direct child of the button object (not a child of the ScreenGui container).

  • Confirm that your button’s Image, HoverImage, and PressedImage properties are set to the appropriate image assets.

Not sure if it works but .activated works for all devices including xbox

When I used MouseButton1Click, it worked although.

See, I have some booths (it is a donation game), whenever a button gets added inside any SurfaceGui, this code would run. That’s why I used Descendants.

You needs just call for two connection MouseButton1Down and TouchTap

1 Like

Use .Activated this works for every device

2 Likes