Ah, the poor little guy is totally emaciated. He's throwing up roaches for any number of reasons, #1 being he's obviously not been fed much at all (your friend fed him once a week, or once a month?) You definitely need to go very, very slowly, and give only small amounts of protein per day in order to slowly build his fat reserves back up, as if he eats too much protein at once you can put him in kidney failure in his condition. Also, large dubias are probably way too big for him in his condition, so that can also cause him to vomit. Much better to use small ones and give 2-3 instead of one large.
He hasn't had a good
UVB light in a long, long time I'm afraid, and this has killed his appetite and most likely caused calcium and vitamin deficiencies. If I were you I'd buy him a Reptisun 10.0 T5 High-Output UVB tube, like a 22" on Amazon.com, and they have a good combo deal for the UVB tube and a long, flourescent fixture rated for a T5 tube at 25 watts. This is the best
UVB light out there for a bearded dragon, and its strong enough to be on top of a mesh lid as long as it is within 11" of his basking spot. That's step one.
I agree you need to ditch the heat mat all together. Why it was on his cool side I don't know, but the idea of the Cool Side is him having an area between 75-80 degrees maximum to cool down. Heat mats are not a great idea for beardies and are unnecessary. They really only need two lights in their enclosures: a long, 18" or 24" (the Reptisun T5 High-Output UVB tube is called a 22") flourescent tube
UVB light rated at 10% minimum (Reptisun 10.0 T5 tube), and right alongside the long UVB tube he needs a bright white basking bulb (never any colored bulbs like blue, red, yellow, etc.) over his basking spot on the Hot Side of his enclosure. Most of us use regular household halogen indoor flood bulbs, like you buy at Lowes, Home Depot, or Walmart. No need for a special reptile basking bulb from a pet shop, most of them are not suitable for a beardie anyway. Make sure both lights are right alongside each other so he can get both at the same time while on his basking spot. A digital probe thermometer is the best way to accurately measure his basking spot (between 98-103 degrees), his Hot Side (between 88-93 degrees), and his Cool Side (between 75-80 degrees maximum). You move the probe to where you want to measure the temperature, let it sit each time you move it for 20-30 seconds, then read the temperature.
At 5 years old he needs fresh greens and veggies every day, collard greens, mustard greens, turnip greens, Dandelion greens, arugula (rocket), endive, escarole, bok choy, and chards are your best choices of greens, stay away from kale and spinach, as it contains oxalates that bind with the Calcium and keep him from absorbing any Calcium. You need a Calcium supplement, if you buy the Reptisun 10.0 T5 High-Output UVB tube your Calcium supplement doesn't need to contain any vitamin D3, as this
UVB light will enable him to make enough D3 on his own. If you choose a weaker
UVB light then you'll need Calcium with D3 (also, the Reptisun T5 High-Output UVB tube only needs replaced once a year, the weaker T8 tubes must be replaced every 6 months, even though they still turn on and light up, they lose their UVB emittance more quickly than the T5).
Dubias are a good protein source, but again he is a very sick and weak boy, and size large dubias are too big I think. If you want to use dubias as his staple feeder insect I'd buy smalls or mediums at the largest, much better to feed a few more than one large one that chokes him, causes an impaction, or causes him to vomit.
For now though, as already mentioned, he can't really handle too much live protein, he needs to have his fat stores rebuilt very slowly as to not damage his kidneys. You need to get some Oxbow Critical Care and syringe feed him daily, along with giving him his fresh greens every day, in order to get his strength back and get him in shape to start eating protein again. He should be taken to an experienced reptile vet ASAP, you need to take a fresh poop sample and have him checked for parasites, and a good reptile vet will help you with the nutritional supplement.
Thanks for wanting to help this little guy, this didn't happen to him in days or weeks, it took months of neglect to put him in this emaciated condition, and it's going to be a slow process getting him back to health, but he's worth it. He deserves to finally have a loving family who will care for him properly.