Issue setting the position of a frame to a client's mouse position

Hello! I am currently working on a pet UI for my game but I’m facing an issue positioning a frame to the client’s mouse position.

-- This is my current code
Frame.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)

Expected result:
image

Current result:

I tried following instructions from all the topics below but none of them worked for me.

Any help is appreciated!

2 Likes

Try to use scale and not offset.

I’ve also got something to work and it stays in the same position as your mouse
Code:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.Move:Connect(function()
	script.Parent.Frame.Position = UDim2.new(mouse.X/mouse.ViewSizeX, 0, mouse.Y/mouse.ViewSizeY, 0)
end)```

This is what I get by using your code:
https://gyazo.com/039a6109bf9365f13c75db13f1754ed3

Is the frame a child of some other frame? Because if so the mouse’s 0,0 position is at the top left of the screen, while the frame’s 0,0 position is at the top left of its parent.

If that’s the issue you can fix by subtracting the parent’s AbsolutePosition from the mouse position.

4 Likes