UserInputService's GetMouseLocation returns incorrect value in BillboardGui InputBegan Callback

Reproduction Steps

Put this code in a LocalScript in the StarterCharacterScripts folder:

local Player = game.Players.LocalPlayer;
local Character = Player.Character;

local bgui = Instance.new("BillboardGui", Player.PlayerGui);
bgui.Adornee = Character:FindFirstChild("Head");
bgui.Size = UDim2.new(0, 50, 0, 50);
bgui.AlwaysOnTop = true;
bgui.Active = true;

local button = Instance.new("TextButton", bgui);
button.Size = UDim2.new(0, 50, 0, 50);

button.InputBegan:Connect(function(inputObject)
	--This first value will print the mouse location relative to the top-left of the BillboardGUI (I think this is a bug), less any GUI inset (also a bug because BillboardGuis don't have GUI inset).
	print("InputObject's Position: ", inputObject.Position);

	--This first value will print the mouse location relative to the top-left of the BillboardGUI, but does not include the GUI inset.
	print("UIS's GetMouseLocation: ", game:GetService("UserInputService"):GetMouseLocation());

	--Spawn a new thread to get the real mouse location. This part has no bug at all.
	spawn(function()
		print("UIS's GetMouseLocation: ", game:GetService("UserInputService"):GetMouseLocation());
	end)
end)

You can mouse over the button stuck to the character’s head and click to see the issue in the output window.

Expected Behavior

I’d expect all three print statements to return the same numbers:

  1. The first (InputObject.Position) should be relative to the screen and NOT include GUI inset, since this is a BillboardGui.
  2. The second (UIS:GetMouseLocation() in InputBegan context) should be relative to the screen.
  3. The third (UIS:GetMouseLocation() in other context) is correct.

Actual Behavior

Three example numbers would be:

InputObject’s Position: 14, -29, 0
UIS’s GetMouseLocation: 14, 7
UIS’s GetMouseLocation: 355, 381

The second is the result of calling GetMouseLocation within the context of InputBegan; the third is the result of calling GetMouseLocation within a newly spawned thread context. The mouse doesn’t move.



Workaround

Spawning a new thread & using GetMouseLocation will give you the correct result.

Issue Area: Engine
Issue Type: Other
Impact: Moderate
Frequency: Constantly
Date First Experienced: 2022-06-06 00:06:00 (-04:00)

By the way, this also applies to InputChanged and InputEnded for a BillboardGui, but does NOT affect ScreenGuis.

1 Like

Thanks for the report, I’m looking into this. Having the result change like this is definitely not the intended behavior.

4 Likes

I enabled a fix for this today, it should return the correct value now.

5 Likes