Dragging along axis with increment

I am attempting to make a dragging system with my own custom handles that players can grab and drag around and that will only move the object in set increments in a single axis. I have it working sort of but as I move the object farther from its origin the mouse gets farther and farther away from the handle. Here is a video of my issue

Id like the handles to stay with the mouse but I can’t seem to figure out how to achieve this, here is my code. Btw the mouse has its target filter set to the handles and the object it’s moving. If that matters.

mouse.Move:Connect(function()
    local dragPos = mouse.Hit.p
    local difference = selectedHandle.CFrame:PointToObjectSpace(dragPos)
		
    local z = math.abs(difference.Z/movementIncrement) + 0.5
    local dist = math.floor(z) * movementIncrement * math.sign(difference.Z)

    if math.abs(dist) > 0 then
        selectedVertice.CFrame = selectedVertice.CFrame *CFrame.new(movementIncrement * math.sign(dist), 0, 0)
    end
end)

Try making only be able to move if the Mouse.Target is on one of the handles
this should stop the mouse from moving off the handle but it will still move to the edge of the handle.
if you do this you may need to set the Mouse.TargetFilter as the object that is being moved.
also hide the handles that are not selected when the object is being moved

i hope this helps.

That doesn’t work, the issue is that I’m calculating the position of the object incorrectly, that’s why its not lining up with the mouse, I’m just not sure how to calculate it correctly.