How To Drag SurfaceGUI Frame?

Whenever the frame is clicked, the frame should follow the mouse pos (relative to the Mouse.Hit.Position, not MS.X,MS.Y), it should drag it but I don’t know why it’s not working.

local MS = game.Players.LocalPlayer:GetMouse()
local Offset

function getPos():Vector2
	local pos = workspace.CurrentCamera:WorldToScreenPoint(MS.Hit.Position)
	
	return pos
end

script.Parent.InputBegan:Connect(function(Input)
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		Offset = script.Parent.AbsolutePosition - getPos()
	end
end)

script.Parent.InputEnded:Connect(function(Input)
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		Offset = nil
	end
end)

MS.Move:Connect(function()
	if Offset then
		local pos = getPos()
		script.Parent.Position = UDim2.fromOffset(Offset.X + pos.X,Offset.Y + pos.Y)
	end
end)

Nevermind, I didn’t know the function returns a Vector3, I fixed it but now something else isn’t working, heres the modified script though.

local MS = game.Players.LocalPlayer:GetMouse()
local Offset

function getPos():Vector2
	local pos = workspace.CurrentCamera:WorldToScreenPoint(MS.Hit.Position)
	return Vector2.new(pos.X,pos.Y)
end

script.Parent.InputBegan:Connect(function(Input)
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		Offset = script.Parent.AbsolutePosition - getPos()
	end
end)

script.Parent.InputEnded:Connect(function(Input)
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		Offset = nil
	end
end)

MS.Move:Connect(function()
	if Offset then
		local pos = getPos()
		script.Parent.Position = UDim2.fromOffset(Offset.X + pos.X,Offset.Y + pos.Y)
	end
end)

It’s not working because when you drag it and then move your camera, the offset isn’t correct anymore, how can I fix this?

Wow, a day and no reply, I honestly expected at least 1 reply
Is this kind of stuff really hard to solve or something?

Try multiplying the pos of the mouse by whatever sensitivity you want. E.g.

script.Parent.Position = UDim2.fromOffset(Offset.X + pos.X*25,Offset.Y + pos.Y*25)

Sadly, this would not work as I want it to be relative to the SurfaceGui, not the camera, so if your Mouse.Hit.Position is on the top right of the SurfaceGui while it is also on the middle of the screen, how would I get the top right position?