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

Make frame follow user mouse?

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

✓ Accepted answer

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.

2 comments

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.

0

Thanks for the tip though, changed it and now it's more smooth :)

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