GuiObject.MouseButton1Click() is a pretty old event that only works with mouse click inputs (afaik).
So I always use this code for my interactive UI elements, whether they are ImageButtons, TextButtons, ImageLabels, TextLabels, etc. Works with all. And works with all device inputs; Console, PC, Mobile!
YourButton.InputBegan:Connect(function(i)
if i.UserInputType ~= Enum.UserInputType.MouseButton1 and i.UserInputType ~= Enum.UserInputType.Touch and i.KeyCode ~= Enum.KeyCode.ButtonA then return end
-- do stuffs
end)
OR
YourButton.InputBegan:Connect(function(i)
if i.UserInputType == Enum.UserInputType.MouseButton1 or i.UserInputType == Enum.UserInputType.Touch or i.KeyCode == Enum.KeyCode.ButtonA then
-- Do stuff
end
end)
Ok, MouseButton1Click should work as I recently made a dungeon lobby thing with all the UI to Join, Create, Leave, and Start a game. I play tested on mobile and laptop and both ways work. Try playtesting on a REAL/Physical mobile device, and try this script:
script.Parent.MouseButton1Click:Connect(function()
local r = math.random(0, 255)
local g = math.random(0, 255)
local b = math.random(0, 255)
script.Parent.BackgroundColor3 = Color3.fromRGB(r,g,b)
end)
I am playtesting on a physical device that’s why i opened this topic, the textbutton does not work for me (I am using Iphone xr) and alongside with some other mobile users too.
I did try it i changed the output to making the frame (textbutton) invisible but it wouldnt work. also i’ll be sending you a game link with the gui right now.
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local SG = game:GetService("StarterGui")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local function OnButtonClick(Button)
print("It was clicked")
Button.Visible = false
end
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local GUIObjs = SG:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y)
for _, obj in pairs(GUIObjs) do
if not obj:IsA("Button") then continue end
OnButtonClick(obj)
end
end
end)