According to the majority of scholars, udhiyah is a sunnah act and is not obligatory. So, if a Muslim can afford it without affecting the debt, he may do it. But if it will affect the loan and ability to repay it, then he should take care to pay back the debt first.