Gird system clips into ground

Hello, so I’ve been having this problem with my build system.

So the problem I’m having is that the grid size is messing up the y and making it clip into the ground.

this is what I currently have

local normal = ray_result.Normal
			local size = block.Size
			local position = ray_result.Position
			local default = position + normal
			
			--local snap_position = Vector3.new(
			--	math.floor(lifted_position.X / grid_size + 0.5) * grid_size,
			--	math.floor(lifted_position.Y / grid_size + 0.5) * grid_size,
			--	math.floor(lifted_position.Z / grid_size + 0.5) * grid_size
			--)

			block.Position = position + normal * (size.Y / 2)

the current problem is when I add grid it will clip it into the ground and I’ve tried many things to fix it but this is the closely I’ve gotten to it so I’m not sure what to do now

I’ve tried many AI and none of them get it right soo I’m asking someone to help

Do you have images to show the extent of the clipping? If you’re raycasting downwards towards the ground, I don’t immediately see how this code would cause clipping.

My only guess would be that maybe normal isn’t actually facing the direction you expect it to be facing?