Snap to grid help

I’m trying to make a placement system and got stuck into a problem for the past 3, basically I have multiple block sizes and I want them to be aligned, but only 4x4x4 are aligned

E.g:

Script I’m using to snap the blocks:

local function GetSnap(Size, Position, Axis)
	if Size[Axis] == 1 then
		return math.floor(Position[Axis]) + 0.5
	else
		return math.floor((Position[Axis] / Size[Axis]) + 0.5) * Size[Axis]
	end
end

local Result = workspace:Raycast(Mouse.UnitRay.Origin, Mouse.UnitRay.Direction * 500, Params)

if Result and Result.Instance then
	local Target = Result.Position + Result.Normal * 1.5
	
	Block.Transparency = 0
	Block.PlaceHighlight.Transparency = 0
	Block.Position = Vector3.new(
		GetSnap(Block.Size, Target, "X"),
		GetSnap(Block.Size, Target, "Y"),
		GetSnap(Block.Size, Target, "Z")
	)
end

Does this

and this

give a .5 stud offset? If yes then, why do it two times? I had a hard time understanding the script due to the lack of comments so maybe this is for a reason. Also I would change

for

because multiplying and dividing by 1 does nothing

the * 1.5 is so its impossible to place blocks in the diagonal
using the formula for all sizes makes it not align with 4x4x4 blocks