Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
RoboFrog 400 Moderation Voter
10 years ago

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!

Locked by adark and Perci1

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
3
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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)
0
Wow, that was a much easier fix than I expected. Thank you for the detailed answer! RoboFrog 400 — 10y
0
No problem c: Perci1 4988 — 10y
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. adark 5487 — 10y
0
Yeah I guess it's two SETS, but there's four numbers which is what I meant. Perci1 4988 — 10y
Ad
Log in to vote
-2
Answered by 10 years ago

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

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) RoboFrog 400 — 10y