MouseButton1Click not working on mobile?

Good Spooky Day!

I have an issue with a script here that works when I’m using it on the PC Version of my game. However when I attempt to use it on mobile they are not working.

wait(1)
player = game.Players.LocalPlayer
button = script.Parent
local plrStage = game.Players.LocalPlayer.leaderstats.Stage.Value
local debounce = false

function teleport()
	if not debounce then
		debounce = true
		local hrp = player.Character.HumanoidRootPart
		local stage = game.Players.LocalPlayer.leaderstats.Stage
		if stage.Value ~= 0 then
		local part = workspace.ObbyStages:FindFirstChild(stage.Value)
			hrp.CFrame = part.CFrame + Vector3.new(0,5,0)		
		end			
	end
end

button.MouseButton1Click:Connect(teleport)
    while true do wait()
	debounce = false
	wait(1)
end

I have an inventory system that functions the same way and I can equip/unequip my pets, but my teleports aren’t working. Any suggestions?

Just to reiterate, it works on PC, But Mobile teleports are not working.

I’m not sure, because I’ve never made a game for mobile, but I think you have to do something else for mobile. I think instead of .MouseButton1Click, it was .Tapped or something. Let me look on the dev hub for it.

2 Likes

wait(1)
player = game.Players.LocalPlayer
button = script.Parent
local plrStage = game.Players.LocalPlayer.leaderstats.Stage.Value
local debounce = false

function teleport()
if not debounce then
debounce = true
local hrp = player.Character.HumanoidRootPart
local stage = game.Players.LocalPlayer.leaderstats.Stage
if stage.Value ~= 0 then
local part = workspace.ObbyStages:FindFirstChild(stage.Value)
hrp.CFrame = part.CFrame + Vector3.new(0,5,0)
end
end
end

button.MouseButton1Click:Connect(function(teleport)
while true do wait()
debounce = false
wait(1)
end

Try this

1 Like

TouchTap it seems, I appreciate it, I’ll try incorporating this into my game so that it works for both mobile and PC

1 Like

Activated event works for both PC and mobile.

1 Like

Yep, that’s what I was looking for. Have a nice day!

But this is MouseButton1Click, not .Activated.

He wanted to work the code on mobile as well.

ButtonGui.Activated

I’ve never seen that before, I didn’t know that was there.

I think this is the one you’re looking for, it works on both PC and mobile.

ButtonGui.Activated

Tried this seems to error out my script. I do appreciate it though.

I don’t use MouseButton1Click for buttons on UI.

Trying the ButtonGui.Activated will let you know

Have you every considered the fact that mobile users cannot connect a mouse to Roblox, causing the MouseButton1Click not to fire?

1 Like

That’s true, it doesn’t fire on Mobile.

Hey, you’re right. .Activated seems to work on both devices. Well, this is something I haven’t seen before. If I ever make a mobile game, I’ll be using this. Guess I learned something new.

2 Likes

I have a gui for my inventory upon hitting to equip items in my inventory, the MouseButton1Click value works. I don’t know why or how but it does.

Replace it with Activated it should be worked.

If you are still having problems, take a look at the Touch events.

As I’m new to the GuiButton.Activate I’m unsure how to incorporate it into my script. But once I figure it out I’ll mark it as the solution if it works for me.