First of all, if there is an infinite loop without a form of a delay, it will crash your game. Change true into wait(). wait() is 0.299999999999 seconds long.
Gui's don't use "Position" like how parts do. They do something called "UDim2".
mainFrame.Position = UDim2.new(0.25, 0, 0.25, 0)
Gui's position isn't close to Vector3.
The next part is mouseX. First we need to find mouse which is in a player. In 2010 they inserted a new method called :GetMouse() so, because this is a local script, we can use something called LocalPlayer. In order to do this we need to go into game.Players. So this is how we could get the mouse from LocalPlayer.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
The last part is the "X" part of mouseX. X is a property of mouse so we need a dot before it. It should look like
mouse.X
Now, with mouse.X we can only follow the X axis. We need to follow the Y axis also.
mouse.Y
Now if we add all this together we should get:
local mouse = game.Players.LocalPlayer:GetMouse()
while wait() do
script.Parent.Position = UDim2.new(0, mouse.X,0, mouse.Y)
end
Let's say the thing that is following your gui is too big, so the mouse goes off your gui, just subtract a certain amount. For example
local mouse = game.Players.LocalPlayer:GetMouse()
while wait() do
script.Parent.Position = UDim2.new(0, mouse.X-65,0, mouse.Y-65)
end
I hope this helps!
7 comments
There's also a
Movedevent that you could use instead of a loop (or you could use mouse.Moved:wait() I suppose). (Excellent answer!)Okay, thanks for the tip!
Thanks! This was really helpful! I'll try it out.
@bluetaslem get 1337 rep .-.
^I'll take a screenshot when he gets 1337 rep.
^ lol okay (sorry about all of the late replies but i forgotht about dis site
@ FunzreyAlt , I didn't take a screen shot of him having 1337 rep, I did take a picture of him having 1234 reputation, lol.