Can't tap SurfaceGui button on mobile

I have a ImageButton under a SurfaceGui which is parented to StarterGui. When clicking the button on a PC, the Activated event fires just as it should.

When doing this on mobile, though, the Activated event doesn’t fire, only rarely (mostly when spam-tapping or right after moving my character - both rare occasions).


Hierarchy:
SurfaceGui%20Button%20Mobile
SurfaceGui screenshot:
SurfaceGui%20screenshot


LocalScript:

wait(3)

local MarketplaceService = game:GetService("MarketplaceService")

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

for _, Descendant in ipairs(script.Parent:GetDescendants()) do
	if Descendant:IsA("ImageButton") then
		if tonumber(Descendant.Name) then
			Descendant.Activated:Connect(function()
				print("Activated")
				
				MarketplaceService:PromptGamePassPurchase(LocalPlayer, tonumber(Descendant.Name))
			end)
		end
	end
end

Each descendant has Active = true if possible and the SurfaceGui has an Adornee set, which is not covered by another invisible part.

I’m trying to prompt a gamepass purchase when one of the buttons gets clicked, but the clicking event just doesn’t get fired on mobile. What am I doing wrong?

5 Likes

I work alongside RT, any help would be appreciated.

This just sounds like buggy behaviour because of mobile interfaces. I’m not sure if there’s much you can do here.

As a workaround fix, try adding events for touchTap and mouseButton1Click individually instead of using activated. The API docs are here.

4 Likes

Seems like TouchTap and MouseButton1Click are combined into Activated, since I found out why the event didn’t register:


This is how each ImageButton is made:
Gamepass_Frame
Gamepass_Frame_Hierarchy


It seems that for mobile (not PC), the TouchTap / MouseButton1Click / Activated events only fire when the cursor clicked a part which wasn’t covered by another GuiObject, like this:
Gamepass_Frame_Clickable
The parts in red are clickable.

I tried setting the ZIndex of the parent ImageButton to a high value but that didn’t change anything.

Is there a way I can keep the frame clickable without having to remove children or having to add another invisible GuiButton with the size 1, 0, 1, 0 so that the entire frame can be clickable?

Just set the Active property of the other elements to false, they’re swallowing the input.

6 Likes

Thanks a lot! That has fixed it.