Looking through all the children doesn't work

Hello,
I’m making Tetris and I need to detect the collisions with every piece.
For that, I’m using:

foreach (Transform child in transform)

But it just detects one child.

My code looks like this

    bool ValidMove()
    {
        foreach (Transform child in transform)
        {
            int roundedX = Mathf.RoundToInt(child.transform.position.x);
            int roundedY = Mathf.RoundToInt(child.transform.position.y);

            if (roundedX < -10 || roundedX >= 0 || roundedY < 0 || grid[roundedX, roundedY] != null)
                return false;
        }
        return true;
    }
}

and I have another piece that looks like this

    void AddToGrid()
    {
        foreach(Transform child in transform)
        {
            int roundedX = Mathf.RoundToInt(child.transform.position.x);
            int roundedY = Mathf.RoundToInt(child.transform.position.y);

            grid[roundedX, roundedY] = child;
        }
    }

None of them work. They detect just one piece of the 4 that all the tetrominos have.

Thank you in advance.

Replace your code with the following loop:

bool ValidMove()
{
	int childCount = transform.childCount;
	for (int i=0; i <= childCount ; i++)
	{
		Transform child = transform.GetChild(i);
		int roundedX = Mathf.RoundToInt(child.transform.position.x);
		int roundedY = Mathf.RoundToInt(child.transform.position.y);

		if (roundedX < -10 || roundedX >= 0 || roundedY < 0 || grid[roundedX, roundedY] != null)
			return false;
	}
	return true;
}