Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make a GUI frame follow the user's cursor?

Currently, I'm working on recreating a failed GUI that I made a few days back, and hit a roadblock when it comes to the title. Currently, I'm using the following lines:

local mouse = game.Players.LocalPlayer:GetMouse()
local gui3 = game.Players.LocalPlayer.PlayerGui.Gui3
gui3.Text.Position = UDim2.new(mouse.X, mouse.Y)

This, to my knowing, is not working. This is contained in a local script, and is in a function which activates when the mouse moves (I'm sure that the function activates properly).

Thank you for reading, and I look forward to finding a solution!

2 answers

✓ Accepted answer

You problem is that UDim2requires four sets of x/y coordinates. It works like this,

UDim2.new(scaleX, offsetX, scaleY, offsetY)

Scale is a percentage, while offset is a specific number of pixels. Which one you use depends on if you want the GUI size and position to vary on different screen sizes or not. Also note that although scale is a percentage, it is converted to a decimal, so you must give it a number between 0 and 1, Much like a part's Transparency.

Since mouse.Y or mouse.X returns a number of pixels, you will probably want to use offset.

UDim2.new(0, mouse.X, 0, mouse.Y)

4 comments

0

Wow, that was a much easier fix than I expected. Thank you for the detailed answer!

0

No problem c:

1

By the way, those aren't "four sets of x/y coords", they are two sets. Additionally UDim2 is literally a set of two UDim values.

0

Yeah I guess it's two SETS, but there's four numbers which is what I meant.

I'll send you a pm on roblox later when I get homeand I'll fix it :)

1 comment

0

I appreciate the kind gesture, but I have already found the solution. (I'm not sure who downvoted you either, in case you're wondering about that)

This discussion is preserved as it was. New answers, comments, and votes are closed.