detect entites in area

how to detect the number of villagers in one small area? id need to make it so that whenever theres 10 villagers in a pit, a command runs

Continue to help post