Comma Before But
A comma should be placed before the word but only if but is at the beginning of an independent clause.
In this sentence, but is being used to mean except. Because but isn’t starting an independent clause, the comma isn’t required.
Because it’s at the beginning of an independent clause, the comma before but is necessary.
from Grammarly Blog https://www.grammarly.com/blog/comma-before-but/