One of the best ways to avoid buying a money pit home is to have a good home inspector look at it for you. A good home inspector will be able to tell you if there are any major repairs that need to be done, and they'll also be able to give you an estimate of how much those repairs will cost.
Another thing to keep in mind is that just because a home looks like it's in great condition doesn't mean that it doesn't have any hidden problems. So always ask the seller for copies of the recent home inspection report and any repair bills that have been paid in the past. That way, you can get a better idea of how much money (if any) needs to be put into.