Hey!
I know this has been asked before but the method is either outdated or I have some settings wrong. I just added a frame to a new gui, and added the following localscript:
local mouse = game.Players.LocalPlayer:GetMouse(); while wait() do script.Parent.Parent.Position = UDim2.new(0, mouse.X, 0, mouse.Y); end
The frame DOES follow the mouse, but very weirdly. It gets offset a little and moves left/right and up/down more and more when you get near the edge of you screen. I want it to always stay on a static point relative to the mouse.
I've seen this done in a few games, so I know it's possible. How can I achieve this?
Since you have the Position being set in a while wait() do
, the movements may seem jittery as it moves every ~1/30th of a second and not whenever the mouse moves.
PlayerMouse
s have an event called Move
, which occurs whenever the mouse moves. This will allow more smooth looking movement.
Here's a sample to get you started on that:
mouse.Move:Connect(function() script.Parent.Position = UDim2.new(0, mouse.X, 0, mouse.Y); end)
Hope this helps you.