It depends on what the plan documents state for your specific 401(k) plan. Some 401(k) plans allow for hardship withdrawals while others do not. In the case your plan does allow for a hardship withdrawal, having an outstanding loan shouldn't affect your ability to take a withdrawal. In fact, some plan documents stipulate that you must first exhaust your loan options before taking advantage of a hardship withdrawal.
Either contact your HR department or check the Summary Plan Description to see if your plan allows for hardship withdrawals.
Feel free to reach out to me with any additional questions.