Accounting for scroll when positioning a GUI parented to a Scroll Frame

The typical way of making a “draggable UI Element” is but using UIS events and determining when you started dragging the UI, recording the current position of either the mouse or the UI and then as the mouse moves find the delta between the two points and changing the position according the that delta value. Let’s say you have a scroll frame; position on a scroll frame doesn’t account for how much you’ve scrolled thus the position of the UI parented to that scroll frame would no longer be accurate to the mouse position or the delta. What would you suggest the best way to account for the change in “scroll” is? I’ve tried using the “canvas position” portion and tried using delta to figure out how much offset to put on the drag position but maybe I didn’t do it correctly?

-- input is the input from UIS changed
-- dragStart is the position of the mouse or UI when its clicked to start dragging

local delta = input.Position - dragStart
UI.Position = UDim2.new(0, delta.X + dragOffset.X, 0, delta.Y + dragOffset.Y)

if input.UserInputType == Enum.UserInputType.MouseWheel then
	dragOffset = dragOffset + Vector2.new(0, CanvasPosition.Y)
end

So far the best I’ve come up with is to attach a function to when the Scroll Frame property “CanvasPosition” changes and then update the offset to the canvas position. It does work but I imagine there’s probably a better way.

ScrollFrame:GetPropertyChangedSignal("CanvasPosition"):Connect(function()
	dragOffset = Vector2.new(0,ScrollFrame.CanvasPosition.Y)
end)