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

Make frame follow user mouse?

Asked by
Nowaha 459 Moderation Voter
5 years ago

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?

1 answer

Log in to vote
7
Answered by
megukoo 877 Moderation Voter
5 years ago
Edited 5 years ago

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.

PlayerMouses 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.

0
I didn't mean it was jittery, it just moves weirdly offset of the mouse, slightly up/down or left/right depending on the position of the cursor and stays there. I don't mean that it lags behind or something. Nowaha 459 — 5y
0
Thanks for the tip though, changed it and now it's more smooth :) Nowaha 459 — 5y
Ad

Answer this question