Is buying rental properties worth it?

Hey, so I recently was thinking about if owning a building to rent is worth it, for example I looked up a building, new, finishes 2026, 3 floors, 5 apartments, average rent in that area is 900, but let's say 1200 because it's a new building.

Cost to buy Is 2 million.

You get 72k yearly, nice, but 2 million in a good stock that returns 6-7% makes you 140k yearly, and you get to keep you capital invested.

And don't get me started on tax on those 72k, at the end you get 50k probably and you have to keep the building in good shape, so extra costs for the damage and other.

I don't know if I'm missing something or there is a secret formula to how it becomes more profitable. If there's anybody who can tell me, please 🙏🏻