When it was Andrea Colon’s turn to ask a question at Mayor Bill de Blasio’s town hall meeting on school safety Thursday, the high school senior got right to the point.

Why is the city “prioritizing police and metal detectors instead of ensuring we have enough social-emotional and mental health support in our schools?” Colon asked the mayor, who had invited roughly 100 students to talk about gun violence and school safety at the Vanderbilt YMCA in Manhattan.

Student after student grilled Mayor Bill de Blasio about metal detectors, just weeks after the mayor said all middle and high schools would be subjected to random screenings. De Blasio made the decision to expand random screenings after a school shooting in Florida that killed 17 people — and ignited a student-led movement for gun control that the mayor has endorsed.

“I don’t think we are making that mistake, honestly,” de Blasio said in response to Colon, noting that he supports programs that target mental health issues.

“I believe we need some police inside and outside of schools at times,” the mayor added. “I think the idea is to create a different relationship” with school police.

Different versions of that back-and-forth played out multiple times during the mayor’s nearly two-hour town hall meeting, highlighting the tightrope de Blasio is trying to walk on school safety.

On one hand, he is sympathetic to advocates who have long raised concerns about the way students of color are policed in schools, and under his leadership, suspensions have declined (though they are still disproportionately issued to students of color). But on the other hand, he has resisted calls to withdraw metal detectors and faced a consistent drumbeat of critics who say schools have become more chaotic under his watch. Those critics seized on a fatal school stabbing in the Bronx earlier this year to make their point.

One Staten Island student, Joe Silverstein, voiced that criticism, asking the mayor to add metal detectors and police officers to more schools. “This would have saved a child’s life in the Bronx a few months ago,” he said.

Still, many more students argued that the city’s metal detector policies make them feel like criminals; school safety officers don’t make them any safer; and there are too few guidance counselors. At one point, the mayor polled the audience, asking if school safety agents created “openness and an environment for dialogue.” Few hands went up.

“We got some work to do, that’s not a shocker,” de Blasio acknowledged.

On multiple occasions, de Blasio tried to steer the conversation away from metal detectors, which he noted are permanent in just 93 of the city’s 1,500 school buildings. After his wife, Chirlane McCray, who co-hosted the town hall, asked what mental health services students wanted to see in schools, the mayor insisted students answer that question before raising their own.

The mayor’s answers didn’t satisfy Ayobami Olabode, who attends Scholars’ Academy in Rockaway Park, Queens. During the town hall, Olabode told the mayor that while a small fraction of schools across the city have metal detectors, most of the high schools in his neighborhood — which serve many students of color — have them.

“He said it’s not a color thing, but I think that it is,” Olabode said after the meeting. “I feel like he tried to brush it off.”

Christina Veiga contributed reporting.