How to make a frame follow your cursor

So I have a computer in my game which uses a surfacegui as the monitors screen. the surfacegui is placed inside startergui with its adornee set to the monitor part. I have an imagelabel inside the surfaceguis main frame (background) which is supposed to follow the players mouse like a cursor. So basically a frame that moves to my mouse position relative to my camera position and rotation and everything else. Can anybody help me with this?

Btw this script doesnt work because the cursor is always off from its actual position:

local mousePosition = game:GetService('UserInputService'):GetMouseLocation()
		
		local viewportSize = workspace.CurrentCamera.ViewportSize

		local relativeX = mousePosition.X / viewportSize.X
		local relativeY = mousePosition.Y / viewportSize.Y

		game.Players.LocalPlayer.PlayerGui.ComputerGui.Screen.Cursor.Position = UDim2.new(relativeX, 0, relativeY, 0)

Try getting the mouse position in screen space and convert that position to a World space position and convert the world space position to the surface gui’s space.

The mousePosition doesn’t account for the inset. GUIs by default do account for it. Disable insets for the ScreenGUI the frame is under. Also, make sure AnchorPoint is centered.

I solved it:

local ray = mouse.UnitRay
local rayDirection = ray.Direction * 500

local monitor = workspace.Computer.Display
local params = RaycastParams.new()
params.FilterDescendantsInstances = {monitor}
params.FilterType = Enum.RaycastFilterType.Whitelist

local result = workspace:Raycast(ray.Origin, rayDirection, params)

if result and result.Instance == monitor then

	local hitPosition = monitor.CFrame:pointToObjectSpace(result.Position)

	local monitorSize = monitor.Size
	local relativeX = (-hitPosition.X / monitorSize.X) + 0.5
	local relativeY = -(hitPosition.Y / monitorSize.Y) + 0.5

	cursor.Position = UDim2.new(relativeX, 0, relativeY, 0)
end
	
cursor.Visible = true

You have to make a function out of this and bind it to RenderStepped