Here is some code to get objects to snap to a grid (in this case 50 pixels wide) after dragging.
local function round(x)
if x%50 ~= 0 then
if x%50 > 25 then
return math.ceil (x / 50) * 50
else
return math.floor(x / 50) * 50
end
end
return x
end
Then you would call the function in the mouse up function like this:
self:setX(round(self:getX()))
self:setY(round(self:getY()))
Hope this is useful!