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.