Make GUI at the exact same position as mouse

Hey everyone! For more simple that it sounds, I can’t find out any help on the forum about how I could make the a GUI follow the mouse at the exact same position as it.

This is important to work, as you may be aware of that custom mouse icons don’t work well while above GUI elements, forcing you to use a fake one. This is the script that I’m currently using:

		moveimage = mouse.Move:Connect(function()
			gui.fake_mouse.Position = UDim2.new(0,mouse.X+0,0,mouse.Y+65)
		end)

as you can see the position is the same while in studio:
image

the same can’t be said while in game (tested in different devices with different resolutions):

Try this


local UIS = game:GetService("UserInputService")
local Mouse = game.Players.LocalPlayer:GetMouse()

local UI = script.Parent
UI.AnchorPoint = Vector2.new(.5,.5)


Mouse.Move:Connect(function()
	UI.Position = UDim2.fromOffset( UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)
end)

1 Like

Not precisely centered, but the position was the same in every resolution. A little tweak on the AnchorPoint did the job, thank you!

Here’s how my script ended up like:

		gui.fake_mouse.AnchorPoint = Vector2.new(.5,0)
		
		moveimage = mouse.Move:Connect(function()
			gui.fake_mouse.Position = UDim2.fromOffset( UIS:GetMouseLocation().X, UIS:GetMouseLocation().Y)
		end)
1 Like

Yea that’s why i have this line in code, so you can adjust it accordingly.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.