Help with block placement system

I’m trying to create a system similar to Piggys build mode, where you’re able to place blocks anywhere on a 3x3 grid. It works perfectly fine when trying to place blocks on certain positions, but when trying to place on others, it goes too far or close.

I’ve seen it work two ways. Checking the surface your mouse is pointing at, and the other using raycasts and ray.normal. I’m trying to not use the surface as I don’t think it would really work.

Current script (not entirely) -

RunS.RenderStepped:Connect(function(Delta)
	Part.Parent = workspace

	if Mouse.Hit and Mouse.Target then
		local Params = RaycastParams.new()
		Params.FilterDescendantsInstances = {Player.Character,Part}
		Params.FilterType = Enum.RaycastFilterType.Exclude

		local Direction = Mouse.Hit.Position - Camera.CFrame.Position
		local ray = workspace:Raycast(Camera.CFrame.Position,Direction,Params)
		
		if ray and ray.Instance and ray.Position then
			print(ray.Normal)
			Part.Position = Vector3.new(math.round(ray.Position.X/3)*3,math.round(ray.Position.Y/3)*3,math.round(ray.Position.Z/3)*3) + (ray.Normal * Part.Size.X)

		end
	end
end)

make that into

(ray.Normal * (Part.Size.X/2))