-- Function to enable dragging for an image button

local function enableDragging(button)
	local dragging = false
	local dragStartPos
	local offset
	local function onMouseButton1Down(x, y)
		dragging = true
		dragStartPos = button.AbsolutePosition
		offset = Vector2.new(x, y) - dragStartPos
	end
	local function onMouseMove(x, y)
		if dragging then
			button.Position = UDim2.new(0, x - offset.X, 0, y - offset.Y)
		end
	end
	local function onMouseButton1Up(x, y)
		dragging = false
	end
	button.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			onMouseButton1Down(input.Position.X, input.Position.Y)
		end
	end)
	button.InputChanged:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseMovement then
			onMouseMove(input.Position.X, input.Position.Y)
		end
	end)
	button.InputEnded:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			onMouseButton1Up(input.Position.X, input.Position.Y)
		end
	end)
end
