Stopping structures from clipping with build system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the spawnpoint to not clip into any parts when the mouse is on the surface

  2. What is the issue? Include screenshots / videos if possible!
    This SpawnPoint thing keeps clipping into the floor


    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    My code:

local function SnapToGrid(position: Vector3)
    local gridStep = 1
    return Vector3.new(
        math.round(position.X / gridStep) * gridStep,
        math.round(position.Y / gridStep) * gridStep,
        math.round(position.Z / gridStep) * gridStep
    )
end

UserInputService.InputChanged:Connect(function(inputObject)
            if inputObject.UserInputType ~= Enum.UserInputType.MouseMovement then
                return
            end

            local mousePosition = UserInputService:GetMouseLocation()
            local rayParams = RaycastParams.new()
            rayParams.FilterType = Enum.RaycastFilterType.Exclude
            rayParams.FilterDescendantsInstances = { spawnClone, player.Character :: any }
            local rayResult = MouseRay(mousePosition, rayParams)

            if not rayResult then
                return
            end

            local _, boundingBoxSize = spawnClone:GetBoundingBox()

            local mousePos = rayResult.Position
            local surfaceVector = rayResult.Normal
            local endPos = mousePos + (surfaceVector * boundingBoxSize / 2)

            local gridPosition = SnapToGrid(endPos)
            spawnClone:PivotTo(CFrame.new(gridPosition))
end)