I will almost replicate my answer, but make it a little broader.
Have different types of physical damage
Many creatures are immune to one type of physical damage, such as Black Pudding is immune to Slashing. Having at least one weapon that you can use from each type (Slashing/piercing/bludgeoning) is usually worth it. If you are low level and short on gold, take the cheap options, 1d4+STR is still more than zero.
If your DM is nice enough to you, magic weapons solve the problem as well.
But that depends on your DM giving you a magic weapon that solves the problem. For example, if you are fighting a Black Pudding, it depends on your DM giving you something with elemental damage. If any damage done by a magic weapon is fine, then simply having any magic weapon is enough. At higher levels, this is the solution that is going to work most of the time, since you might have accumulated enough items if your DM was kind to your party.
Silver Weapons
Many monsters are affected by non-magic weapons as long as they are silver-coated. It shouldn't be too expensive to get some silver-coated weapons.
Gather Intel
You should know where you are heading - and your party can do some research on what should be effective there. You know you are going into a cave full of skeletons, and someone in the city should be able to tell you that a Mace is more effective than a Shortsword against them.
Multiclassing
Well, this one is an optional rule and should be done carefully to not be awful, but yeah, some classes rely TOO MUCH in only physical damage. Multiclassing into something that can deal some magic damage, or buff your weapon so it is treated as magical, should work.
You can't and don't need to be useful every fight
As I mentioned in the other answer, if you are a melee fighter (without a magic weapon) against a Black Pudding, you just run. It is clearly designed to wreck melee fighters and your rangeds should be doing the job. It is slow and can be kitted efficiently, most of the time.
Obviously that doesn't mean "do nothing the entire fight" - check what other actions you can do to help. Aid/help is a possible action to give your ranged members constant advantage. Yes, it feels lackluster to just help the other guys in the fight, but well, it is also lackluster to be the guy with 8 CHA in the heavily social part of the game, and it is lackluster to be a skill monkey in most combat situations. Point being you should be used to situations where you can't shine at all and the spotlight is for someone else.