I assume you’re trying to make a tiling placement system. For that you could use math.floor
local part = "part"
local model = "model"
local grid = 1 -- the grid you're trying to achieve. 1 = 1x1, 2 = 2x2 and so on.
local function Snap(part, position)
local newVec = Vector3.new(
math.floor(position.X / grid + 0.5) * grid,
position.Y + part.Size.Y/2, --[[ this will make sure that
that your part will be on the surface of your mouse hit. You can use "math.floor(position.Y / grid + 0.5) * grid" if you don't want that]]
math.floor(position.Z / grid + 0.5) * grid
)
return newVec
end
part.CFrame = CFrame.new(Snap(part, mouse.Hit.Position)) -- move a single part to desired location
model.PrimaryPart.CFrame = CFrame.new(Snap(model.PrimaryPart, mouse.Hit.Position)) -- move a model to desired location assuming that PrimaryPart isn't nil
this should allow you to move parts or models in a grid, tho I suggest you to visit this link:
it explains everything about grid placement, rotating and more in a more efficient way.
I also suggest to read more about CFrame and Math