I got it to work!
local module = {}
local TweenService = game:GetService("TweenService")
local function ConvertAbsoluteToScale(gui, targetObject, anchorPoint)
local containerAbsolutePos = gui.AbsolutePosition
local containerAbsoluteSize = gui.AbsoluteSize
local frameAbsolutePos = targetObject.AbsolutePosition + (targetObject.AbsoluteSize * anchorPoint)
local frameRelativePos = frameAbsolutePos - containerAbsolutePos
return UDim2.fromScale(frameRelativePos.X / containerAbsoluteSize.X, frameRelativePos.Y / containerAbsoluteSize.Y)
end
function module.MoveTo(guiObject, targetObject, speed, gui, test)
local origin = guiObject.AbsolutePosition
local targetOrigin = targetObject.AbsolutePosition
local targetAnchorPoint = targetObject.AnchorPoint
local targetPosition = ConvertAbsoluteToScale(gui, targetObject, targetAnchorPoint)
local distance = (targetOrigin - origin).Magnitude
local duration = distance / speed
local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tween = TweenService:Create(guiObject, tweenInfo, {Position = targetPosition})
tween:Play()
return tween
end
return module