How do i implement grid placement?

Can someone help me with grid placement. If you would like me to show a part of the current placement script, i can. But i would like to know how to change the object movement to a grid. The object is controlled from the mouse.

Divide the input position by the grid size, round each component, then multiply by the grid size. The resulting position will be a multiple of the grid components.

--inPos is the input position from the user
local snappedPos = Vector3.new(math.round(inPos.X / grid), math.round(inPos.Y / grid), math.round(inPos.Z / grid))* grid

Thanks, also what variable is connected to “grid” since when i inserted that code into the game it couldnt identifiy what it is.

You have to choose the grid value. It is a number.

Okay so i imported it into the script and it came up with this error.

local ObjectAngles = CFrame.Angles(0, math.rad(RotatingAmount), 0)
local grid = 2
local ObjectCFrame = Vector3.new(math.round(mouse.Hit.Position.X / grid), math.round(mouse.Hit.Position.Y / grid + PrevieuwObject.PrimaryPart.Size.Y / 2), math.round(mouse.Hit.Position.Z / grid))* grid

PrevieuwObject:SetPrimaryPartCFrame(ObjectCFrame * ObjectAngles)

do

local ObjectAngles = CFrame.Angles(0, math.rad(RotatingAmount), 0)
local grid = 2
local ObjectCFrame = Vector3.new(math.round(mouse.Hit.Position.X / grid), math.round(mouse.Hit.Position.Y / grid + PrevieuwObject.PrimaryPart.Size.Y / 2), math.round(mouse.Hit.Position.Z / grid))* grid
local CFF = CFrame.new(ObjectCFrame) * ObjectAngles
PrevieuwObject:SetPrimaryPartCFrame(CFF)

you can’t make Vector3 * CFrame

just put the vector3 inside a cframe. Example:

local ObjectCFrame = CFrame.new(Vector3.new(math.round(mouse.Hit.Position.X / grid),math.round(mouse.Hit.Position.Y / grid + PrevieuwObject.PrimaryPart.Size.Y/2),math.round(mouse.Hit.Position.Z / grid))* grid)