Note: I initially posted this to the scripting help forum. I’m crossposting here because this is a genuine engine bug.
I came across a VERY weird bug while coding a popup screengui for a billboard gui. The initial goal was to have extra info pop up over the player’s mouse when they moused over a button on a certain billboard gui.
Whenever you get the values from the player’s mouse, you get wrong values while in the scope of a .MouseEnter or .MouseMoved event.
local mouse = game.Players.LocalPlayer:GetMouse() someTextButton.MouseEnter:Connect(function () local mousePosX, mousePosY = mouse.X, mouse.Y --would give wrong values end)
The most interesting part of this, is that if you instead get the mouse values from a different scope, like a coroutine at the end of the function, you get the correct values.
local cooroo = coroutine.wrap(function () while true do print(mouse.X..","..mouse.Y) --would print the CORRECT mouse position wait(1) end) cooroo()
I set up a file that shows the problems with getting the correct mouse X and Y values. There are two guis, a billboard gui that is adorned to a part in workspace and a screen gui that will be positioned at the mouse when you hover over the billboard gui’s button. The gui should be wrongly positioned somewhere else in this demo.
In the console you should see the mouse values printed from both the .MouseMoved event and the looping coroutine. mouseProblem.rbxl (17.9 KB)
Also here’s a screenshot if you don’t want to download the file for the source code: