If your car is totaled and you still owe money on the loan, the insurance company will pay your lender for the car's value, and you will be responsible for any remaining balance if the check is less than the loan amount. If you have gap insurance, it will cover the difference between the car's value and the loan balance. Otherwise, you will need to continue making payments for as long as it takes to bring your loan balance to zero.
If your car is totaled and another driver is at-fault, their liability insurance will pay for the car's value up to their policy limits. If you were at fault, you can file a collision claim. After you receive a settlement from the insurance company, you can determine if you still have a balance left on your loan.
After your lender has gotten the insurance check, you can file a gap insurance claim immediately, assuming you previously purchased coverage and still owe money to your lender. Be sure to follow any instructions in your policy. For instance, some gap insurance policies instruct you to continue making payments to your lender until the claim can be processed.
Unfortunately, your options are limited if you don't have gap insurance and your total loss check does not cover your loan balance. You can try to negotiate with the insurance company to have them increase their estimate of your car's value. However, you will need evidence that your car was worth more than the insurer calculated, and there is no guarantee that you will get more money. Otherwise, you are stuck continuing to make payments, though you could try asking your lender for a payment plan.