While churches struggle to stem a well-documented exodus of membership from their pews, new research suggests that that the people leaving may be missing out. A massive new study from the research pros at Barna and Christian nonprofit World Vision has found a link between going to church and better mental health.

The finding is just one of many from The Connected Generation, which surveyed 15,369 18- to 35-year-olds across 25 countries. The study found some worrisome narratives, suggesting that while today’s young people may be more connected than any in history, they also struggle with more loneliness, anxiety and existential questions than previous generations.

But one thing that seems to really make a difference is regular church attendance. About 34 percent of people who have no faith said they were optimistic about the future, compared to 51 percent of practicing Christians who say the same.

Likewise, about 29 percent of people who do not practice any faith say they feel “able to accomplish goals,” compared to 43 percent of practicing Christians.

“The research reveals a generation of driven adults who are wary and weary, wrestling with questions, longing for deeper relationships and facing significant societal, professional and personal obstacles,” wrote Alyce Youngblood, Barna’s editorial director and senior writer for the study. “Yet, we also found that faith is one important factor associated with their well-being, connection and resilience. When—or, for many, if—they walk into a church, they’ll need concrete teaching from leaders they can trust and meaningful opportunities to contribute to a faith community.”