.Activated and MouseButton1Click not working for mobile users

Hello!

Simple question, the .Activated and .MouseButton1Click event for button objects simply do not seem work on mobile.

For example,

script.Parent.Activated:Connect(function()
	muted = not muted
	if muted == true then
		script.Parent.Top.Text = 'Unmute Music'
		script.Parent.Sound.Volume = 0
	else
		script.Parent.Top.Text = 'Mute Music'
		script.Parent.Sound.Volume = 0.5
	end
end)

Nothing happens when using Roblox’s mobile “emulator”, however using the normal play test does work.

1 Like

IIRC the event is deprecated, is there a reason why you’re using it at all versus methods such as MouseButton1Click? And to answer your question, there could be many reasons on why that’s the case, you’d have to explain further.

1 Like

No particular reason, however I have tried MouseButton1Click and that seemed not to work, which is why I tried moving over to .Activated to see if that was any better.

It’s not any better, MouseButton1Click is recommended actually. In any case to answer your question, I just ran a test and yes the Activated event seems to work just fine on mobile. Like I said there could be many reasons, some to consider would be the following:

  • Are you using ContextActionService?
  • Are you sure that you’re code to handle the event is even running? (aka are you sure it’s not yielding beforehand)
1 Like

Not using CAS, and no yields before the event. Here’s the full script, decided to use this as it’s quite basic:

local muted = false

script.Parent.Activated:Connect(function()
	print('asdasd')
	muted = not muted
	if muted == true then
		script.Parent.Top.Text = 'Unmute Music'
		script.Parent.Sound.Volume = 0
	else
		script.Parent.Top.Text = 'Mute Music'
		script.Parent.Sound.Volume = 0.5
	end
end)

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Top.Visible = false
	script.Parent.Bottom.Text = script.Parent.Top.Text
end)

script.Parent.MouseButton1Up:Connect(function()
	script.Parent.Top.Visible = true
	script.Parent.Bottom.Text = ''
end)

script.Parent.MouseLeave:Connect(function()
	script.Parent.Top.Visible = true
	script.Parent.Bottom.Text = ''
end)

Try using UserInputService instead as that gives the best compatibility for mobile here you can read more about the functions and UserInputService itself!

UserInputService

You’d also want to use Tool.Equipped instead of Tool.Activated if you are to use UserInputService.

1 Like

I’m using .Activated on a UI here, not a tool.

I don’t think that’s what the OP is talking about… There is an old deprecated event on GUIButtons called Activated. UserInputService would not be of any use in this case.

1 Like

Oh alright my bad,I am not really sure why this isn’t working your code seems to be perfectly fine.

Try deleting the MouseButtonUp and Down events listners to see if that makes a change. Otherwise, it could have to do with external factors. Just make sure it’s a LocalScript under the button in PlayerGui and it should function properly.

1 Like

Click Billboard UI through the mobile buttons - #8 by 4slug Pretty sure this guy had the same issue.

1 Like

It’s a LocalScript, and it is under PlayerGui. Removing the listeners didn’t work. The strange thing is that the .MouseButton1Down and up both work.

That’s a BillboardGui, I’m looking for an actual screen UI.

I don’t see the issue here in that case. How are you certain that it isn’t working, I just checked and it seems to be working perfectly fine. Can you record a gif of both your workspace and the output so I can better visualize the situation?

1 Like

What I suggest in this case is testing to see if the issue is within the function itself, probably try running the .Activated event to print something and see if that works

Sure, let me just get that ready.

Here’s a screenshot of the hierarchy of PlayerGui. The localscript is where the button controller is.

Testing on computer

With mobile “emulator”:

On my actual phone:

I’ve tried that and nothing was printed.

Try setting the active property for all the UI elements to false

1 Like

I tried it and the same thing happened.

Try creating a new ScreenGUI with a TextButton and the same .Activated event, print anything to see if that event actually works.

1 Like