I have a button that makes a player’s skin tone change and the button works fine on computer:
But on mobile I click once and it takes the money but then I have to click again for the tan to apply:
Script:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats.Shells.Value >= 45 then
game.Workspace.PurchaseSuccessful:Play()
game.ReplicatedStorage.Purchase:FireServer(45)
local folder = script.Parent.Parent -- Name your folder -- in screenGui
local remote = game.ReplicatedStorage:WaitForChild("SkinColour2") -- Event
for i, button in pairs(folder:GetChildren()) do
if button:IsA("GuiButton") then
button.MouseButton1Up:Connect(function()
print("ColorChanging")
remote:FireServer(button.BackgroundColor3)
script.Parent.Text = ("Purchasing...")
script.Parent.Parent.Parent.Parent.ApplyingTan.Frame:TweenPosition(UDim2.new(0.272, 0, 0.035, 0),"Out","Quint",1)
script.Parent.Parent.Parent.Parent.BeachTanThing.Frame.ExitButton.Visible = false
script.Disabled = true
wait(5)
script.Parent.Parent.Parent.Parent.ApplyingTan.Frame:TweenPosition(UDim2.new(0.272, 0, -0.5, 0),"In","Quint",1)
script.Parent.Parent.Parent.Parent.BeachTanThing.Frame.ExitButton.Visible = true
script.Parent.Text = ("Purchased")
end)
end
end
else
game.Workspace.PurchaseFailed:Play()
script.Parent.Text = ("Insufficient funds!")
wait(3)
script.Parent.Text = ("Purchase for 45 Shells...")
end
end)
This is how my GUI is set up:
Use the “TouchTap” event from the “UserInputService” to handle touchscreen devices instead of “MouseButton1Click”.
https://developer.roblox.com/en-us/api-reference/event/GuiObject/TouchTap
1 Like
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
script.Parent.MouseButton1Click:Connect(function()
if UIS.TouchEnabled then
return
end
if player.leaderstats.Shells.Value >= 45 then
game.Workspace.PurchaseSuccessful:Play()
game.ReplicatedStorage.Purchase:FireServer(45)
local folder = script.Parent.Parent -- Name your folder -- in screenGui
local remote = game.ReplicatedStorage:WaitForChild("SkinColour2") -- Event
for i, button in pairs(folder:GetChildren()) do
if button:IsA("GuiButton") then
button.MouseButton1Up:Connect(function()
print("ColorChanging")
remote:FireServer(button.BackgroundColor3)
script.Parent.Text = ("Purchasing...")
script.Parent.Parent.Parent.Parent.ApplyingTan.Frame:TweenPosition(UDim2.new(0.272, 0, 0.035, 0),"Out","Quint",1)
script.Parent.Parent.Parent.Parent.BeachTanThing.Frame.ExitButton.Visible = false
script.Disabled = true
wait(5)
script.Parent.Parent.Parent.Parent.ApplyingTan.Frame:TweenPosition(UDim2.new(0.272, 0, -0.5, 0),"In","Quint",1)
script.Parent.Parent.Parent.Parent.BeachTanThing.Frame.ExitButton.Visible = true
script.Parent.Text = ("Purchased")
end)
end
end
else
game.Workspace.PurchaseFailed:Play()
script.Parent.Text = ("Insufficient funds!")
wait(3)
script.Parent.Text = ("Purchase for 45 Shells...")
end
end)
script.Parent.TouchTap:Connect(function()
if player.leaderstats.Shells.Value >= 45 then
game.Workspace.PurchaseSuccessful:Play()
game.ReplicatedStorage.Purchase:FireServer(45)
local folder = script.Parent.Parent -- Name your folder -- in screenGui
local remote = game.ReplicatedStorage:WaitForChild("SkinColour2") -- Event
for i, button in pairs(folder:GetChildren()) do
if button:IsA("GuiButton") then
button.MouseButton1Up:Connect(function()
print("ColorChanging")
remote:FireServer(button.BackgroundColor3)
script.Parent.Text = ("Purchasing...")
script.Parent.Parent.Parent.Parent.ApplyingTan.Frame:TweenPosition(UDim2.new(0.272, 0, 0.035, 0),"Out","Quint",1)
script.Parent.Parent.Parent.Parent.BeachTanThing.Frame.ExitButton.Visible = false
script.Disabled = true
wait(5)
script.Parent.Parent.Parent.Parent.ApplyingTan.Frame:TweenPosition(UDim2.new(0.272, 0, -0.5, 0),"In","Quint",1)
script.Parent.Parent.Parent.Parent.BeachTanThing.Frame.ExitButton.Visible = true
script.Parent.Text = ("Purchased")
end)
end
end
else
game.Workspace.PurchaseFailed:Play()
script.Parent.Text = ("Insufficient funds!")
wait(3)
script.Parent.Text = ("Purchase for 45 Shells...")
end
end)
You can use the GuiButton | Roblox Creator Documentation event to handle activation from all devices instead of just mouse input.
1 Like
Does MouseButton1Up not work on mobile bc I’ve been using only mousebutton1click and no touch tap for any buttons and it works perfectly fine on mobile
MouseButton1Click will work on mobile.
1 Like
the script works it jsut doesnt fix the problem i think it has something to do with this: button.MouseButton1Up:Connect(function()
but idk how i would fix that
MouseButton1Up doesn’t fire on touchscreen devices.
1 Like
Is there a mobile equivalent to MouseButton1Up
?
I tried all of these but they dont work