Positive experiences or new opportunities could stop him. Maybe meeting someone new who inspires him, or having a chance to do something he's always dreamed of could change his perspective and make him see that life has more to offer.
Snape could also offer Harry some form of protection or a safe space. Maybe he allows Harry to stay in his office for a while, away from the prying eyes and pressures of Hogwarts. He might brew a special potion for Harry to calm his nerves and help him think more clearly. In addition, Snape could share some of his own experiences of dealing with difficult times, making Harry realize that he's not alone in his struggles.
It could also be related to his past traumas resurfacing all at once. Naruto has had a difficult childhood with being ostracized. If on his birthday, memories of all those painful times come flooding back and combine with a current difficult situation, like a failed relationship or a broken friendship, it could push him to the edge and lead to his suicide in the fanfiction.
The kid might be facing serious bullying, family problems or feeling a lack of purpose. To prevent it, we need to offer support, show love and make them feel valued.
Tanjiro might use his sense of smell to detect hidden threats. Since his sense of smell is super - enhanced, he could sniff out any demons or traps in the way of saving Rengoku. For example, if there are demons disguised as allies, Tanjiro would be able to tell by their scent.
One possible reason could be extreme guilt. Maybe he fails to protect his friends in a major battle and feels so responsible that he can't bear it. For example, if Sasuke were to die because Naruto couldn't reach him in time, Naruto might sink into such deep guilt that he sees no way out but death.
It could also be due to a sense of isolation. If all his friends turned against him for some reason, perhaps being wrongly accused of a heinous crime. Naruto, who values his bonds deeply, might find such a situation unbearable and choose to end his own life.