Prayers are offered July 8, 2016, in Thanks-Giving Square in Dallas for the five police officers killed and the seven injured in the city by a sniper the previous night. (Erik S. Lesser/European Pressphoto Agency)

In the hours after a Minnesota police officer shot school cafeteria manager Philando Castile during a traffic stop Wednesday evening, the teachers who worked with Castile — and the parents who knew him — endured waves of shock and grief.

And then, alongside their own tumult of emotion, they began grappling with how to explain Castile’s death to the children who loved him.

Anna Garnaas, a teacher at the St. Paul, Minn., elementary school where Castile worked, is already anticipating what she will hear from her first-, second- and third-grade students when they return to class in the fall.

“I think that’s when we’ll see them crying and wondering and asking questions, the first day of school in September,” she said. “Where’s our buddy? Where’s the guy who takes care of us and makes sure we have our most fundamental needs met?”

Amid spasms of violence between police officers and communities they are sworn to serve, this is the job of parents and teachers across the country: Help children make sense of the senseless. Teach them how to process questions that the entire nation is struggling to answer, questions that are bound up with the country’s complex history of race and racism: Why is this happening? What can we do about it?

And particularly in communities of color where tension with police is not just something children see on the news, but also is an experience they live: How can we keep people safe?

These were difficult questions in 2014, when Eric Garner on Staten Island and Michael Brown in Ferguson, Mo., died in encounters with police. They remained pressing questions in 2015, when an officer shot Walter Scott in North Charleston, S.C., and when Freddie Gray died of a spinal injury he suffered while in police custody in Baltimore.

And the questions became even more tangled and urgent in the past week, when in the span of three days, police killed Alton Sterling in Louisiana and Castile in Minnesota, and a young black man, saying he was angry about such violence, responded by shooting 12 officers in Dallas, killing five. The Dallas attack is one of the worst against police in the nation’s history.

Even as these events leave adults grasping for answers, they also affect children, who need somewhere to take their confusion and their sadness, experts say. Schools need to be one resource to which they can turn.

“Schools can make such a big difference, even without having the answers,” said Deborah Menkart, executive director of the Washington-based nonprofit Teaching for Change. “Just being a space where every person’s humanity is acknowledged and there’s a chance to discuss it and it’s not something that’s left outside the school doors.”

The anger felt by young people, particularly young people whose families or friends have been touched by violence, is real and visceral. “They’re slaying us like animals,” Allysza Castile, Philando Castile’s sister, told The Washington Post on Thursday.

Melissa Reeves, president of the National Association of School Psychologists, said children will learn from the reactions of adults around them, including their parents and teachers. “It’s okay to be angry,” Reeves said. “But what’s important is how you use that anger in a way that’s going to be peaceful and part of a positive solution.”

Laura Fuchs, a teacher of U.S. history and government at the District’s H.D. Woodson High School, said she teaches about how government institutions work and about the long struggles and the successes of nonviolent social movements. It’s a way to show young people how they can channel their anger about violence into positive change, she said.

“We look at a lot of civil rights activists from the past and the present and how it is always young people who propel these issues forward,” Fuchs said. “Hopefully, they can be inspired by others, and be able to think about, ‘What can my role be? How can I be part of the solution?’ ”

Fuchs said she also feels a responsibility to help her students, many of whom are African American, to stay safe in the world as it is.

She grapples with that particularly when she teaches about the Fourth Amendment’s prohibition against unreasonable searches and seizures: She wants students to know and protect their constitutional rights. But she also wants them to be careful not to provoke a police officer’s anger or fear.

She tells them that if they think they have been stopped illegally or are being searched illegally, they should assert that they do not consent to the search. But if the police persist, they should submit, she tells them. And never, ever run.

“It’s not fair that they have to be so careful when interacting with authority figures, but they do,” she said.

Steven Berkowitz, an associate professor of clinical psychiatry at the University of Pennsylvania, said schools should deliver one simple message to children younger than 8: “This is all very complicated, but our job is to keep you safe. And that’s what we are going to do as adults.”

But schools can teach older children how instances of police violence are part of broader societal patterns and problems, he said. And schools can give students a way to approach police departments with constructive criticisms and in that way play a critical role in changing their communities’ relationships with police.

But like Fuchs, Berkowitz said that teachers and parents should help students think through not just how they want to change the world, but also how to avoid violence.

Schools should teach young people that violence almost always arises out of fear, when the rational part of the brain shuts down, he said. So what does that mean for a young person caught in a tense situation with a police officer?

“You do exactly what the cop says. You don’t give them any reason to feel afraid,” Berkowitz said. “To have to say that to a kid is a terrible thing. But that’s the reality.”

He said he had not yet come to grips with how schools should help children understand and respond to the shooting of police officers in Dallas on Thursday night.

But he said it is important that schools be unequivocal in stating that violence is wrong.

“There is never a justification for shooting or killing somebody when you are not in danger,” he said. “There’s no justification.”