This might help...
http://gdl.graphisoft.com/tips-and-tricks/creating-custom-label-frame/
You could also interrogate a drawing view title to see how that is put together.
There is a scale bar object in the UK library but I couldn't get it to work logically. Could be worth checking the code to see if it offers any pointers.
Going back to basics I don't see how a scale bar in paper space could shown anything other than 1:1 units, this makes sense as it allows some less digitally savvy operators to print to the right size (recent issue for me). If you have a view at 1:50 and another detail at 1:20 how should the scale bar react?
For me the only logical solution for an adaptive scale bar is to place it in the view where it can adjust to the GLOB_SCALE variable.
One final observation while you are trying to resolve the scale bar you may find you drawings carry a big disclaimer "DO NOT SCALE"...
Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)