Your lender will still be owed the full value of your loan even if you get into an accident and your vehicle is totaled. There are a couple of different scenarios that may occur after an auto accident.
If the other driver was at fault, their property damage liability insurance should pay for the full value of the vehicle (up to their policy limit). That money would go toward paying off the remainder of your loan. You would get to keep the remainder and put it toward a new vehicle purchase. If you owe more than what you are paid by the claim, you will still owe the remaining amount after the insurance company has paid your lender.
If you’re at fault for the accident and you have collision coverage, then you can file a claim and your insurance should pay out the value of your vehicle. That money would go to your lender, and you would get to keep whatever is left.
If you’re at fault and you don’t have collision coverage, you will not be paid anything from the insurance company and you will still owe the remainder of the loan value to your lender.