Placement system problems. How should I fix this?

Hello! I am working on a game that allows you to place blocks and that stuff. The blocks are based off of a 0.75 stud grid. I want these blocks to not clip inside of each other like the following screenshot. How can I fix this?
image

I have already done this:
(The code below basically detects if the players mouse is hitting the surface of another block. If it is, then it just puts the block on the side of that block)

	--if mouse.TargetSurface == Enum.NormalId.Front then
								--	finalcf = CFrame.new(mouse.Target.Position+(mouse.Target.CFrame.LookVector)*3)
								--elseif mouse.TargetSurface == Enum.NormalId.Back then
								--	finalcf = CFrame.new(mouse.Target.Position+(mouse.Target.CFrame.LookVector*-3))
								--elseif mouse.TargetSurface == Enum.NormalId.Top then
								--	finalcf = CFrame.new(mouse.Target.Position+(mouse.Target.CFrame.UpVector*3))
								--elseif mouse.TargetSurface == Enum.NormalId.Bottom then
								--	finalcf = CFrame.new(mouse.Target.Position+(mouse.Target.CFrame.UpVector*-3))
								--elseif mouse.TargetSurface == Enum.NormalId.Left then
								--	finalcf = CFrame.new(mouse.Target.Position+(mouse.Target.CFrame.RightVector*-3))
								--elseif mouse.TargetSurface == Enum.NormalId.Right then
								--	finalcf = CFrame.new(mouse.Target.Position+(mouse.Target.CFrame.RightVector*3))

But players can resize blocks in the game, so if I were to use the code above, then the block would be locked onto resized blocks like this.
image

See if this has the features you need?: GridPlacer: Highly-featured module for part placement, rotation, and snapping to grid

Yeah it does, but I don’t think it would work out with what I already have coded in the game.