MouseButton1Click not working on mobile?

Oh, it works just like MouseButton1Click.

Yeah I’ve changed the script to accompany the activated instead of MouseButton1Click and it works on pc but still not on mobile D: I’ll keep digging.

wait(1)

player = game.Players.LocalPlayer

button = script.Parent

local debounce = false

function teleport()

if not debounce then

debounce = true

local HumanoidRootPart = player.Character.HumanoidRootPart

HumanoidRootPart.CFrame = game.Workspace.Levels.Lobby.LobbySpawn.CFrame + 
Vector3.new(0,5,0)

end

end

button.Activated:Connect(teleport)

while true do wait()

debounce = false

wait(1)

end

Then it might not be that, it might be something else. Try putting prints in between each line to see where it goes wrong.

You should implement your Debounce system.

MouseButton1Click doesn’t work on mobile if I recall correctly when trying to use it on other devices, as it defines on the name “MouseButton” it can be used on mouses or anything that can be clickable like a laptop or a console, and not on a phone.

So, using this with the script won’t return/call the function as it will only work on laptops/desktops.

Recommendation? I would use Instance.TouchTap as that will work on tablets and phones, you might want to add a different function using Instance.TouchTap and one with MouseButton1Click for it to work on different occasions. I’ve made a code sample and how to use it correctly:

local Button = script.Parent
local Debounce = false

local function TapOn()
    if not Debounce then
        Debounce = true
        Button.Text = "Howdy!"
    else
        wait(1)
        Debounce = false
        Button.Text = "Hi."
    end
end

Button.TouchTap:Connect(TapOn)

What are we doing here? First, we’re calling the local variables of the button like TextButton and adding a debounce so the user isn’t spamming, and then we make our local function so it can run when we add our :Connect() at the bottom. We add some lines and strings and add an else when tapped again.

Some articles to help you out in the future:

TextButtton Article.
TouchTap Article.

1 Like

I believe it is activated. Also the functions are firing when I join the game So I’ll need to work that out

I made few modifications.


local player = game.Players.LocalPlayer
local Character = player.Character

Character.CharacterAdded:Wait()

button = script.Parent

local debounce = false

function teleport()

if not debounce then

debounce = true

local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart ~= nil then

HumanoidRootPart.CFrame = game.Workspace.Levels.Lobby.LobbySpawn.CFrame + 
Vector3.new(0,5,0)

end
end
end

button.Activated:Connect(teleport)

while true do wait()

debounce = false

wait(1)

end





1 Like

So I’ve got my code in addition to the MouseButton1Click for TapOn using my relevant code. I’m using the emulator and its not firing despite what I believe to be error free code. I literally just added an additional call using the same function as seen below.

local player = game.Players.LocalPlayer

local button = script.Parent

local debounce = false

function teleport()

if not debounce then

debounce = true

local HumanoidRootPart = player.Character.HumanoidRootPart

HumanoidRootPart.CFrame = game.Workspace.Levels.Lobby.LobbySpawn.CFrame + Vector3.new(0,5,0)

print("Lobby button fired")

end

end

button.MouseButton1Click:Connect(teleport)

button.TouchTap:Connect(teleport)

while true do wait()

debounce = false

wait(1)

end

I’ll also add that it still fires on PC but doesn’t fire on my call for TouchTap

Implement your Debounce system it may the one causing it.

1 Like

I apologize for all the questions and stuff but I believe my debounce system is actually active in the script. Or if I’m misreading your reply. Could you explain a bit further. Also as stated previously it works with my PC but when I use emulator, the TouchTap is not firing.

Again I’m sorry for all the confusion on my part.

1 Like

Please use backquotes and indentation to format the code.

1 Like

Shot in the dark, But could it be because it’s housed in a UIGridLayout? does that not work well with the mobile aspect?

image

I fixed it. roundify zindex as well as button zindex were both set to one, I iset the button to two and it fires on mobile now.

Thank you everyone who helped. I’d like to mark all of you as the solution but, If someone finds this and is having the same issue I’d like them to know what I did to fix it.

4 Likes