Mouse position does not update properly on mobile devices if a button is pressed

If you click a button and get the mouse position at that moment using UserInputService, you would find that the location of the mouse is incorrect (shown as a red dot). You are only able to get the correct mouse location one frame after the button press (shows as a blue dot).

Testing on an iPhone 13:

The studio emulator also imitates this behaviour when emulating any mobile device:

Code used:

local UIS = game:GetService("UserInputService")

local ActualPosition = script.Parent.ActualPosition --> red dot
local CorrectPosition = script.Parent.CorrectPosition --> blue dot

script.Parent.ImageButton.MouseButton1Down:Connect(function()
	ActualPosition.Position = UDim2.fromOffset(
		UIS:GetMouseLocation().X,
		UIS:GetMouseLocation().Y
	)

	task.wait() --> correct mouse position is updated one frame later
	
	CorrectPosition.Position = UDim2.fromOffset(
		UIS:GetMouseLocation().X,
		UIS:GetMouseLocation().Y
	)
end)

Testing Stuff.rbxl (43.8 KB)

Expected behavior

Retrieving the mouse location on mobile returns the correct location directly after a button is pressed.

4 Likes

Thanks for the report! We’ve filed a ticket in our internal database.

2 Likes

This should be fixed now. Thanks!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.