When you start missing payments on your mortgage the bank will report those defaulted payments to the credit bureau's and that will put a ding in your credit score.
Then once the foreclosure starts the bank will once again report your default on the mortgage to the credit bureau again and it will again lower your credit score.
I know things happen but make sure that you can afford the house you're buying and don't buy more house than you can actually afford.
There's a saying that people say for people who buy houses they can't afford and it's called being house poor.