Detect mouse movement in certain direction does not work correctly on mobile

--------------------This is in a localScript
local detect = script.Parent.detect --this goes to an imageButton that is the child of a surfaceGui that is attacted to a block

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mouseX

detect.MouseButton1Down:Connect(function()
	mouseX = mouse.X
end)

detect.MouseButton1Up:Connect(function()
	local diffX = mouseX - mouse.X
	if diffX > 80 or diffX < -80 then
		if diffX < 0 then			
			print("right")
			mouseX = nil
		elseif diffX >= 0 then			
			print("left")
			mouseX = nil
		end
	end
end)

This works fine on PC. But on mobile, this will work but if I try again in the same direction as the previous, it will not work. Another issue that only happens on mobile is I can just click on either side of the surfaceGui without dragging and it will still run.

You should set ‘mouseX’ to ‘mouse.X’ not ‘nil’.

1 Like

Tried it and it didn’t change anything.

I tried putting a print in the mouseButton1Up function both before the first if statement and after. The first print before the if statement works. the one inside the if statement does not.