Gui Buttons Not Working On Mobile?

Okay, the code seems to be just fine. Is there any errors that you receive from the output?

1 Like

nope its all clear for some reason

Ok, let’s do some debugging.

Add print(ā€œButton is pressedā€) after your first line of code. Test run it, and see if the output did print.

Basically pressing the button while testing, it should print.

1 Like

added it, and it only prints on computer

In that case, we would need to use UserInputService. Have you ever used UserInputService?

Actually you know what, just add TouchTap:Connect(function() to the same function.

Below is alternative option.

Here’s the link to UserInputService,

Basically, you can combined multiple keybinds such as desktop key and mobile touch (tap) and Xbox controller sync to the same button.

1 Like

i havent ever used userinputservice but its strange cuz before the guis always work with mousebutton1click

MouseButton1Click will always work for Desktop devices. But it will not work for Mobile because they both have different keybindings.

But wait, there’s a better way. You would need to change the coding around a bit.

Instead of script.Parent.MouseButton1Click

wrap it as a function and use MouseButton1Click(function)
as well as TouchTap:Connect(function) to sync into one function.

If that make sense.

1 Like

it doesent work touchtap doesent work on any device

If you are using mouseclick I don’t think it will work I haven’t tried it

1 Like

My apologies for late response, but here it is.

local Button = script.Parent
local MainFrame = Button.Parent
function UpdateUI()
	if MainFrame.HatsFrame.Visible == false then
		MainFrame.HatsFrame.Visible = true
		MainFrame.COLOR.Visible = true
		Button.Text = "Hats - On"
	else
		MainFrame.HatsFrame.Visible = false
		MainFrame.COLOR.Visible = false
		Button.Text = "Hats - Off"
	end
end
Button.MouseButton1Click:Connect(UpdateUI)
Button.TouchTap:Connect(UpdateUI)

Use MouseButton1Down instead

script.Parent.MouseButton1Down:Connect(function()
    if script.Parent.Parent.HatsFrame.Visible == false then
        script.Parent.Parent.HatsFrame.Visible = true
        script.Parent.Parent.COLOR.Visible = true
        script.Parent.Text = "Hats - On"
    else
        script.Parent.Parent.HatsFrame.Visible = false
        script.Parent.Parent.COLOR.Visible = false
        script.Parent.Text = "Hats - Off"
    end
end)
3 Likes