UI buttons not functioning on mobile

I have just made a shop gui that will automatically put in a shop box for every item in a folder. The buttons work fine on computer, but it does not work on mobile. I have used ImageButtons, but I switched to ImageLabels and TextButtons for hope. But that does not work either. Can you help?

Core LocalScript
-- Core UI localscript

local availableTools = game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
local mainFrame = script.Parent:WaitForChild("MainFrame")
local safeArea = mainFrame:WaitForChild("SafeArea")
local itemInformation = safeArea:WaitForChild("ItemInformation")
local infoFrame = itemInformation.InfoFrame
local selectedItem = itemInformation.SelectedItem
local equippedItem = itemInformation.EquippedItem
local numberOfItems = #availableTools

local itemFrame1 = safeArea.SwordFrame
local shopButton = script.Parent:WaitForChild("ShopButton")
local buyButton = infoFrame.BuyButton
local equippedItemViewport = script.Parent:WaitForChild("EquippedItemViewport")
local itemViewport = itemInformation.ItemViewport


game.ReplicatedStorage.SendEquipped.OnClientEvent:Connect(function(equipped)
	equippedItem.Value = equipped
	if equippedItem.Value ~= "" then
		local fakeCam = Instance.new("Camera")
		fakeCam.Parent = equippedItemViewport
		local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(equippedItem.Value.."Handle"):Clone()
		handle.Parent = equippedItemViewport
		equippedItemViewport.CurrentCamera = fakeCam
		fakeCam.CFrame = handle.CameraCFrame.Value
	end
end)

-- WRITE YOUR CODE AFTER THIS LINE, DO NOT PUT IT IN THE COMMENT

shopButton.MouseButton1Click:Connect(function()
	if mainFrame.Active == true then
		mainFrame.Active = false
		mainFrame:TweenPosition(UDim2.new(-0.5,0,0.5,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true)
	elseif mainFrame.Active == false then
		mainFrame.Active = true
		mainFrame:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true)
	end
end)

local PADDING_X = 0.02
local DROPDOWN_Y = 0.2
local DROPDOWN_X = 0.25

local item11 = itemFrame1:WaitForChild("Item1")
local itemButton11 = item11:WaitForChild("ItemButton1")

local box 
local numRows = 1

for i = 1,numberOfItems,1 do

	if i == 1 then
		box = item11
	else
		box = item11:Clone()
		box.Name = "Item"..i
		box.Parent = itemFrame1

		if (i-1) / (4*numRows) == 1 then
			-- New row
			numRows = numRows + 1
			box.Position = UDim2.new(PADDING_X,0,box.Position.Y.Scale,0) + UDim2.new(0,0,DROPDOWN_Y *(numRows - 1))
		else
			-- Add to the X only
			box.Position = itemFrame1["Item"..(i-1)].Position + UDim2.new(DROPDOWN_X,0,0,0)
		end
	end

	box.ItemButton1.MouseButton1Click:Connect(function()
		for _, v in pairs(itemViewport:GetChildren()) do
			if not v:IsA("Frame") then
				v:Destroy()
			end
		end

		local itemViewportCam = Instance.new("Camera")
		itemViewportCam.Parent = itemViewport
		
		print("looking for :",availableTools[i][1].."Handle",": in",game.ReplicatedStorage:WaitForChild("ToolModels"):GetChildren())
		local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
		handle.Parent = itemViewport

		itemViewport.CurrentCamera = itemViewportCam
		itemViewportCam.CFrame = handle.CameraCFrame.Value

		local owned = game.ReplicatedStorage.ItemCheck:InvokeServer(availableTools[i][1])
		if equippedItem.Value == availableTools[i][1] then
			infoFrame.Cash.Text = "Owned"
			infoFrame.BuyButton.Text = "Unequip"
		elseif owned == true then
			infoFrame.Cash.Text = "Owned"
			infoFrame.BuyButton.Text = "Equip"
		else
			infoFrame.BuyButton.Text = "Buy"
			infoFrame.Cash.Text = "$"..availableTools[i][2]
		end

		infoFrame.ItemName.Text = availableTools[i][1]
		selectedItem.Value = availableTools[i][1]

		for _, v in pairs(itemFrame1:GetChildren()) do
			if v:IsA("ImageButton") then
				v.BorderSizePixel = 0
			end
		end

		itemFrame1["Item"..i].BorderSizePixel = 2

	end)
	
	local fakeCam = Instance.new("Camera")
	fakeCam.Parent = box.VPF
	local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
	handle.Parent = box.VPF
	box.VPF.CurrentCamera = fakeCam
	fakeCam.CFrame = handle.CameraCFrame.Value
	itemFrame1["Item"..i].ItemName.Text = availableTools[i][1]
end

buyButton.MouseButton1Click:Connect(function()
	local result = game.ReplicatedStorage.PurchaseItem:InvokeServer(selectedItem.Value)
	if result == true then
		buyButton.BackgroundColor3 = Color3.fromRGB(18, 223, 25)
		buyButton.Text = "Success"
		wait(0.5)
		buyButton.Text = "Equip"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	elseif result == "NotEnoughCoins" then
		buyButton.BackgroundColor3 = Color3.fromRGB(204, 31, 31)
		buyButton.Text = "Not enough coins"
		wait(0.5)
		buyButton.Text = "Buy"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	elseif result == "Equipped" then
		equippedItem.Value = selectedItem.Value
		buyButton.BackgroundColor3 = Color3.fromRGB(18, 223, 25)
		buyButton.Text = "Equipped"
		wait(0.5)
		buyButton.Text = "Unequip"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	elseif result == "Unequipped" then
		equippedItem.Value = ""
		buyButton.BackgroundColor3 = Color3.fromRGB(18, 223, 25)
		buyButton.Text = "Unequipped"
		wait(0.5)
		buyButton.Text = "Equip"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	end
end)

if equippedItem.Value ~= "" then
	local fakeCam = Instance.new("Camera")
	fakeCam.Parent = equippedItemViewport
	local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(equippedItem.Value.."Handle"):Clone()
	handle.Parent = equippedItemViewport
	equippedItemViewport.CurrentCamera = fakeCam
	fakeCam.CFrame = handle.CameraCFrame.Value
end

equippedItem:GetPropertyChangedSignal("Value"):Connect(function()
	if equippedItem.Value ~= "" then
		for _, v in pairs(equippedItemViewport:GetChildren()) do
			if not v:IsA("Folder") then
				v:Destroy()
			end
		end
		
		local fakeCam = Instance.new("Camera")
		fakeCam.Parent = equippedItemViewport
		local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(equippedItem.Value.."Handle"):Clone()
		handle.Parent = equippedItemViewport
		equippedItemViewport.CurrentCamera = fakeCam
		fakeCam.CFrame = handle.CameraCFrame.Value
	else
		for _, v in pairs(equippedItemViewport:GetChildren()) do
			if not v:IsA("Folder") then
				v:Destroy()
			end
		end
	end
end)

2 Likes

instead of using mousebutton1click use textbutton.Activated.

1 Like

Just saying: textbutton.Activated won’t work. Use MouseButton1Click/MouseButton1Down/MouseButton1Up

2 Likes

why?

chars chars chars chars chars

1 Like

Activated is used for tools and not for TextButtons in Guis

it does work.
check the api before making a claim.

i wont check the api bc you just now said that it does

That isn’t the problem in this script. MouseButton1Click works on PC and Mobile.

1 Like

I don’t see anything wrong in this script, does any errors pop up in the output?

Can you show how it looks on mobile?

Use TextButton Cause MouseButton1click is generally for PC User.

At about 0:06, I would start clicking it. And no errors are in the output.

Hm that’s weird, other buttons worked on mobile but those specifically don’t work. You tried switching it to regular text buttons right?

Would you like me to upload the gui so you can interact with it and see what’s wrong?

Sure. If you wouldn’t mind. Just publish it as a place and I can just test it.

shop.rbxm (32.5 KB) Here is all the things the shop will interfere with.

Activated is a property on buttons AND tools. Dont spread false information.

Hey, sorry for the late reply, I’ve been busy over the break and never looked at the forum till now. Anyway, not sure if you wanted me to check the codes GUI only, since its the only UI there. If you wanted me to test the shop UI, resend a file link with it.

Sorry, I accidentally named it that, It is the right gui though.

Thanks for backing me up : )

Finally, a good user on the devforum

1 Like