[HELP]Moving on mobile causes a “screen tapped” event

I have this script that works perfectly on a computer but when you play on mobile, and you just swipe the joystick to move, it triggers the event. I was wondering if there was a way to make this stop and if there is some sort of value I need to check before firing the server?… It also happens when zooming in/out, jumping, and rotating the camera. Help would be greatly appreciated!

Here is a video of the problem:

In the video, I never once just tapped. It was only me move the joystick and camera movements.
(When you tap, it charges the power, and when you tap a second time, it releases it)

Here is the client side of the script:

local UIS = game:GetService(“UserInputService”)
local player = game.Players.LocalPlayer
local event = game.ReplicatedStorage:WaitForChild(“Magic”)
local mouse = player:GetMouse()
local down = false
local denounce = false 

mouse.Button1Down:Connect(function()
down = true
end)
mouse.Button1Up:Connect(function()
if down == true then
down = false 
If debounce == false then
debounce = true
event:FireServer()
wait(0.05)
debounce = false
end
end
end)

Please help if you know a solution.
Thanks,
@LlCHTENBERG

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local event = game.ReplicatedStorage:WaitForChild("Magic")
local mouse = player:GetMouse()
local down = false
local debounce = false 
local isTouchscreen = UIS.TouchEnabled

mouse.Button1Down:Connect(function()
	if isTouchscreen then
		return
	end
	if not down then
		down = true
	end
end)

mouse.Button1Up:Connect(function()
	if isTouchscreen then
		return
	end
	if down then
		down = false 
		if not debounce then
			debounce = true
			event:FireServer()
			wait(0.05)
			debounce = false
		end
	end
end)

I fixed a few other issues too, like “denounce” at the top of the script, the format and the capital “If”.

2 Likes
UIS.TouchTap:Connect(function(pos, proc)
	if proc then
		return
	end
	if not debounce then
		debounce = true
		event:FireServer()
		wait(0.05)
		debounce = false
	end
end)

Add this if you want to support touchscreen devices.

3 Likes

Sorry about the script errors. I didn’t have the Orin script with me and I was typing it on mobile so with autocorrect bad auto-capitalization, you know how it is. Also, I will give you the solution as soon as I test it.