If you want a car to get in and drive and nothing else, then a BMW is not for you. Especially a E39.
If you want a car that is good to drive and are prepared to seek out what maintenance you should be doing, then do it, it is a good buy. Generally they a good car to work on and someone else has probably had every issue you will face and written it up the fix here.
An e39 is like a beautiful wife, needs constant attention, lots of money, lets you down at the worse times but you’d never be without it.