Ask an Astronomer is run by volunteers in the Astronomy Department at Cornell University. We answer your astronomy questions. Please browse our archive first.
You have less than four months before everything on the surface is dead. However, in D&D the Underdark, especially the deep Underdark might continue to be survivable. You'd certainly want to seal any tunnels to the surface ASAP once people were down there. Underdark ecosystems may even continue to function relatively normally for a very long time, but really you're probably going to be wanting to be opening portals or using existing perma-portals to evacuate the planet.
It really depends on the nature of your world. If it's a real-world style planet, looks like Ruin Explorer has you covered. But are there other factors at play in a D&D planet? Might there be magic capable of helping people live long term without a Sun? Or might the world's heat simply not come (only) from the Sun? Perhaps the Sun simply isn't necessary for the world to keep turning- maybe enough food can be harvested from fungus-based ecosystems (e.g. the Underdark) to keep things going, or people can quickly adapt to farm fungal food sources.
And that doesn't even address the non-planetary options. My campaign setting is set on the inside surface of an enormous bubble of water, and the Sun is an artificial object that orbits a specific island at a distance of half a million miles. It provides significant light and heat, but people survived before it existed, so it would be possible to go on after it was gone.
Anyway, I think the consequences in most settings would be grave. I suspect that most of the survivors would tend to be in larger cities, where higher level individuals and more magical resources are likely more available. Which leads to interesting knock on effects- if the outlying places tend to die out, and those are usually where the urban centers get their food, do the cities survive, or do they just die slower?
Which brings up one more element: time. The effects will be scary but not lethal in the first few days, but escalate over time. What percentage of the population dies depends on how long the Sun has been dead for.
Is the sun a giant ball of nuclear reactions many many times larger than your world providing vast amounts of energy? Or is it a chariot that is driven across the sky daily? Would make a big difference for if it went out, though one of them is more fantasy.