Why my draggable gui double it position? [Solved]

I am trying to make draggable gui with custom module but it seems my gui is doubling the positon

i have to try to change to mouse moved but still same problem

Function for the updating:

local function Drag()
		local DragStart = class.Widget:GetRelativeMousePosition() -- vector 2
		local StartPosition = Gui.Position -- vector2
		local function Update(input)
			
			local DeltaPos =  input - DragStart
			print(Gui.Position, StartPosition)
			Gui.Position = UDim2.fromOffset(Gui.Position.X.Offset + DeltaPos.X, Gui.Position.Y.Offset + DeltaPos.Y) -- offset

Function for the moving & disconnecting:

local connection = Gui.MouseMoved:Connect(function(x,y)
				Update(Vector2.new(x,y))
		end)
		
		Gui.InputEnded:Once(function()
			connection:Disconnect()
		end)

Video:

To fix my code i just update DragStart after update is called.
Function for the moving & disconnecting:

local connection = Gui.MouseMoved:Connect(function(x,y)
			Update(Vector2.new(x,y))
			DragStart = class.Widget:GetRelativeMousePosition() -- vector 2
		end)
		
		Gui.InputEnded:Once(function()
			connection:Disconnect()
		end)

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