How would i snap parts to a 1x1 grid?

Trying to make a placement system, but want to snap the parts to a 1x1 stud grid

heres what i have currently

-- Varibles
local Player = game:GetService("Players").LocalPlayer
local RunService = game:GetService("RunService")

local Mouse = Player:GetMouse()

local PlotModule = require(game.ReplicatedStorage.Modules.plotHandler)

local ServerPlaceEvent = game.ReplicatedStorage.Events.PlaceEvent
local PlaceEvent = game.ReplicatedStorage.Events.StartPlace

local PlacementPart = game.ReplicatedStorage.Items.AreaPart:Clone(); PlacementPart.Size = Vector3.new(1,1,1)

local CurrentPart
local v	
local Pos

-- Functions
local function RVector(Pos)
	return Vector3.new(math.floor(Pos.X), math.floor(Pos.Y), math.floor(Pos.Z))
end

local function MovePart()
	local PSize = PlacementPart.Size
	Pos = RVector(Mouse.Hit.p) + Vector3.new(0,PSize.Y/2,0)
	PlacementPart.Position = Pos
end

local function ReadyPlacing(PartSize)
	if CurrentPart and PartSize == CurrentPart then
		RunService:UnbindFromRenderStep("MovePart")
		PlacementPart.Parent = game.ReplicatedStorage.Items
		CurrentPart = nil
		return
	end
	
	if CurrentPart and PartSize ~= CurrentPart then
		RunService:UnbindFromRenderStep("MovePart")
	end
	
	CurrentPart = PartSize
	
	if PartSize == "1x1" then
		v = Vector3.new(1,1,1)
	elseif PartSize == "2x2" then
		v = Vector3.new(2,2,2)
	end
	
	PlacementPart.Parent = workspace
	PlacementPart.Size = v
	
	RunService:BindToRenderStep("MovePart", 1, MovePart)
end

local function PlacePart()
	if CurrentPart then
		ServerPlaceEvent:FireServer(v, Pos)
	end
end

-- Main

-- Event Functions
PlaceEvent.Event:Connect(ReadyPlacing)
Mouse.Button1Down:Connect(PlacePart)

(Edit)
Tried using math.round

local function RVector(Pos)
	return Vector3.new(math.round(Pos.X), math.round(Pos.Y), math.round(Pos.Z))
end

didnt really work for part sizes besides 2x2

(Edit 2)
Changed .round to .floor

local function RVector(Pos)
	return Vector3.new(math.floor(Pos.X), math.floor(Pos.Y), math.floor(Pos.Z))
end

Still having issues with the parts not snapping onto the grid correctly, not to easy to explain but heres a video

Using math.floor(), we can achieve this.

how exactly would i use math.floor here?

Documentation on how-to-use math functions. Best go with math.floor(x).

return Vector3.new(math.round(Pos.X), math.round(Pos.Y), math.round(Pos.Z))

I’ve used code similar to this in my own placement systems to snap models to a 1x1 grid and it worked fine.

alright i figured out what it does, althought how does this benefit me? changed math.round to .floor and it still has the same probably where not all sized parts snap in the same places

its not positioning different sized parts the same for me, i think only 2’s line up to the edge for me

That foundation brick needs to be snapped to a 1x1 grid too, i.e; position Vector3.new(0, 0, 0) and size Vector3.new(10, 1, 10).

image
it is, i dont think height really matters here

Yeah, height doesn’t matter since you’re using the mouse’s hit position.

It was something with the block, not sure but trying to move it by 1stud wasnt the best as even though the main area was all in a 1x1 grid and the part was 1x1 setting the parts posiiton to the corner would put it at .5 somehow

so just used this code from

Vector3.new((Pos.X - Pos.X % GridSize), (Pos.Y - Pos.Y % GridSize), (Pos.Z - Pos.Z % GridSize))

and just set gridsize to .5 and it works somewhat, doesnt snap at weird positions but its now at .5 instead of 1

Also need help on moving the part so you can place them side by side without the part going inside the other

Could still use some help on this :pray: