Roblox MouseButton1Click does not fire when pressing on Mobile

Hello. I’ve been using MouseButton1Click event for a while when dealing with TextButtons, and in the past they always worked when a player presses them on mobile. But for some reason, my studio-member s notified me that they can’t press the play button. It works on PC, not on mobile. Here is my code:

local button = script.Parent.Button;

local frame = script.Parent;

local debounce = false;

local function mouse_Enter()
	local tweenService = game:GetService("TweenService");

	local tweenInfo = TweenInfo.new(0.15);

	tweenService:Create(frame, tweenInfo, {
		Size = UDim2.new(0.266, 0,0.119, 0);
		Rotation = 0;
	}):Play()
end;

local function mouse_Leave()
	local tweenService = game:GetService("TweenService");

	local tweenInfo = TweenInfo.new(0.3);

	tweenService:Create(frame, tweenInfo, {
		Size = UDim2.new(0.296, 0,0.133, 0);
		Rotation = 0;
	}):Play()
end;

local function button_Down()
	local tweenService = game:GetService("TweenService");

	local tweenInfo = TweenInfo.new(0.1);

	tweenService:Create(frame, tweenInfo, {
		Size = UDim2.new(0.246, 0,0.11, 0);
	}):Play()
end;

local function button_Up()
	local tweenService = game:GetService("TweenService");

	local tweenInfo = TweenInfo.new(0.1);

	tweenService:Create(frame, tweenInfo, {
		Size = UDim2.new(0.266, 0,0.119, 0);
		Rotation = 0;
	}):Play()
end;

local function on_Click()
	game.SoundService.Click:Play()
	
	if debounce then return end;
	
	debounce = true
	
	local tweenService = game:GetService("TweenService");

	local tweenInfo = TweenInfo.new(0.3);
	
	tweenService:Create(script.Parent.Parent.AroundCredits, tweenInfo, {
		BackgroundTransparency = 1;	
	}):Play()
	
	tweenService:Create(script.Parent.Parent.AroundPlay, tweenInfo, {
		BackgroundTransparency = 1;	
	}):Play()
	
	wait(tweenInfo.Time)
	
	script.Parent.Parent.AroundCredits.TextLabel.Visible = false
	
	script.Parent.Parent.AroundPlay.TextLabel.Visible = false
	
	tweenService:Create(script.Parent.Parent.LogoImage, TweenInfo.new(2, Enum.EasingStyle.Bounce, Enum.EasingDirection.In), {
		Position = UDim2.new(0.5, 0, -0.5, 0);
	}):Play()
	
	wait(2)
	
	tweenService:Create(script.Parent.Parent.MainBlue, TweenInfo.new(0.4), {
		ImageTransparency = 1;
	}):Play()
	
	script.Parent.Parent.Parent.Intro.Enabled = true
	
	local succed = pcall(function()
		local starterGui = game:GetService("StarterGui");
		
		starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
	end)
	
	wait(0.4)
	
	script.Parent.Parent.Enabled = false
end;

button.MouseEnter:Connect(mouse_Enter)

button.MouseButton1Down:Connect(button_Down)

button.MouseButton1Click:Connect(on_Click)

button.MouseLeave:Connect(mouse_Leave)

button.MouseButton1Up:Connect(button_Up)

Mobile test:


** It’s working perfectly on computer **

1 Like

It looks like your…

button.MouseButton1Down:Connect(button_Down)

only changes the button UI.

Try changing it to…

button.MouseButton1Down:Connect(on_Click)

or add a function that does what you want (ie, close the UI) and place it into both on_Click & button_Down functions.

It works on PC devices, but not on mobile. All the rest of the events that I used fire perfectly.

it’s because it’s MOUSEbutton1clicked.
there should be an event for a UI button for mobile players. as soon as it has “touch” in the event name, it’s for mobile.

I believe mobile uses MouseButton1Down, in this case, it is doing exactly what you want. (button_Down is tweening the size of the Play button)

I use the exact same event for other buttons, and it works perfectly on mobile devices.

Textbutton.TouchTap

That should help.

1 Like

I already used it, and it still didn’t work.
I believe this is an engine bug

   local function button_Down()
local tweenService = game:GetService("TweenService");

local tweenInfo = TweenInfo.new(0.1);

tweenService:Create(frame, tweenInfo, {
	Size = UDim2.new(0.246, 0,0.11, 0);
}):Play()
end;

button.MouseButton1Down:Connect(button_Down) -- You only change the 'Play' button's tween when it's tapped.

I do not really understand, will that have any influence on the issue that I am experiencing?

When it’s tapped, as shown in the video you provided, the button will change it’s size but not close because you only set it to change it’s size and not close.

You’d have to use what is inside of your function ‘on_Click’ within your function ‘button_Down’.

function on_Click() = Mouse

function button_Down() = tap/Mouse down

Yes. But MouseButton1Click works on all of the other UIs that I have in my game on mobile

MouseButton1Click does work on mobile (for textbuttons, imagebuttons)

I’m 90% sure your issue is is that MouseEnter is effecting, or “Overriding” the MouseButton1Click

In mobile MouseEnter, and MouseLeave is the equivalent of MouseButton1Down and MouseButton1Up

basically MouseEnter and MouseButton1Click in mobile devices are both triggered by taps. Your solution would be to not connect the MouseEnter event for mobile users

1 Like

Something you could try, your whole script, except when a mobile player taps play it will do just the intended function (on_Click), PC will do everything.

local button = script.Parent.Button;

local frame = script.Parent;

local debounce = false;

local isMobile = game:GetService('UserInputService').TouchEnabled;

local function mouse_Enter()
local tweenService = game:GetService("TweenService");

local tweenInfo = TweenInfo.new(0.15);

tweenService:Create(frame, tweenInfo, {
	Size = UDim2.new(0.266, 0,0.119, 0);
	Rotation = 0;
}):Play()
end;

local function mouse_Leave()
local tweenService = game:GetService("TweenService");

local tweenInfo = TweenInfo.new(0.3);

tweenService:Create(frame, tweenInfo, {
	Size = UDim2.new(0.296, 0,0.133, 0);
	Rotation = 0;
}):Play()
end;

local function button_Down()
local tweenService = game:GetService("TweenService");

local tweenInfo = TweenInfo.new(0.1);

tweenService:Create(frame, tweenInfo, {
	Size = UDim2.new(0.246, 0,0.11, 0);
}):Play()
end;

local function button_Up()
local tweenService = game:GetService("TweenService");

local tweenInfo = TweenInfo.new(0.1);

tweenService:Create(frame, tweenInfo, {
	Size = UDim2.new(0.266, 0,0.119, 0);
	Rotation = 0;
}):Play()
end;

local function on_Click()
game.SoundService.Click:Play()

if debounce then return end;

debounce = true

local tweenService = game:GetService("TweenService");

local tweenInfo = TweenInfo.new(0.3);

tweenService:Create(script.Parent.Parent.AroundCredits, tweenInfo, {
	BackgroundTransparency = 1;	
}):Play()

tweenService:Create(script.Parent.Parent.AroundPlay, tweenInfo, {
	BackgroundTransparency = 1;	
}):Play()

wait(tweenInfo.Time)

script.Parent.Parent.AroundCredits.TextLabel.Visible = false

script.Parent.Parent.AroundPlay.TextLabel.Visible = false

tweenService:Create(script.Parent.Parent.LogoImage, TweenInfo.new(2, 
Enum.EasingStyle.Bounce, Enum.EasingDirection.In), {
	Position = UDim2.new(0.5, 0, -0.5, 0);
}):Play()

wait(2)

tweenService:Create(script.Parent.Parent.MainBlue, TweenInfo.new(0.4), {
	ImageTransparency = 1;
}):Play()

script.Parent.Parent.Parent.Intro.Enabled = true

local succed = pcall(function()
	local starterGui = game:GetService("StarterGui");
	
	starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
end)

wait(0.4)

script.Parent.Parent.Enabled = false
    end;

    if (isMobile == true) then
    button.MouseButton1Click:Connect(on_Click)
    else
      button.MouseEnter:Connect(mouse_Enter)
      button.MouseButton1Down:Connect(button_Down)
      button.MouseButton1Click:Connect(on_Click)
      button.MouseLeave:Connect(mouse_Leave)
      button.MouseButton1Up:Connect(button_Up)
      end

Perhaps try making the functions under the “button.MouseButton1Click:Connect(function()” instead of connecting the function after. This doesn’t make much sense, however Roblox can be weird sometimes.

What do you mean it is overidding it?

It doesn’t really matter. :Connect() requires 1 argument which is a function, both of them are functions.

Can you explain your concept in simple words? I do not understand what you did here that made a difference

local isMobile = game:GetService('UserInputService').TouchEnabled;

if (isMobile == true) then -- If the player is using a mobile device
button.MouseButton1Click:Connect(on_Click)
else -- if they are not using a mobile device
  button.MouseEnter:Connect(mouse_Enter)
  button.MouseButton1Down:Connect(button_Down)
  button.MouseButton1Click:Connect(on_Click)
  button.MouseLeave:Connect(mouse_Leave)
  button.MouseButton1Up:Connect(button_Up)
  end

While I do suggest switching to a more “proper” service for handling user input, what I can imagine happening here is based on the MouseButton1Click caveat - To count as a Click event the “mouse” must click down AND release on the object. That is to say, if for some reason you click down and move off the object and release it will not fire off a Click event. Potentially the tweening of the button going smaller and the position that the person is releasing their finger just so happens to be not over the button anymore, thus not firing the Click event.

This could be compounded by a possible z-Indexing issue also if you have frames layered above the button or other GUI elements that may be interfering with input absorption.

I would suggest (other than switching to a full UserInputService approach) that you up the zIndex of the button and make sure that they are releasing their finger centered over the button. Just a thought and hopefully that is it.

The only way I was able to reproduce this issue was releasing my finger as the button got smaller.