"If a law had been given that could impart life, then righteousness would certainly have come by the law." (Galatians 3:21)
The reason you can't earn righteousness has nothing to do with your failure to behave perfectly. The reason you can't earn righteousness is because God doesn't demand payment. He only seeks to give freely.