There are people who tried to use the law to earn their salvation. But God showed me this. Do you know the Litmus Test is used to identify acid (acidity) and base (alkalinity)? If the Litmus paper turn red, it is an acid. If it turn blue it is a base. The law is the same as the Litmus test. Everyone is born a sinner but they do not know it. So God put the 10 commandments as a Litmus test to show us that we are all sinners. If you break any of the 10 commandments even once in your life, then you know you are a sinner. The law is not meant to save but just as a means to identify sinners. By obeying the 10 commandments and sin lesser does NOT turn you from a sinner into a righteous saint. Just like the Litmus test, an acid is identify when it turn red. Regardless how red (very red or pinky light red) it turn the litmus paper, it is still an acid.
Ephesians 2:8-9 For it is by grace you have been saved, through faith—and this is not from yourselves, it is the gift of God—not by works, so that no one can boast.
There can be any number of reasons for doing good works other than for the goal of earning our salvation, the Bible speaks in favor of correct reasons and against incorrect reasons, so we should be careful not to mistake what is said against the incorrect reasons as being against the correct reasons. In other words, there is a world of difference between these two statments:
1.) Our salvation requires us to choose to do good works.
2.) Our salvation requires us to choose to do good works for the purpose of earning our salvation as a wage.
While there are many verses that deny #2, such as Romans 4:5, there are many verses that support #1, such as Romans 2:13, so there must be a reason that our salvation requires us to choose to do good works other than for the purpose of trying to earn it as a wage, such as faith. Our salvation is from sin (Matthew 1:21) and sin is the transgression of God's law (1 John 3:4), so while we do not earn our salvation by obeying it, living in obedience to it is nevertheless intrinsically part of the concept of Jesus saving us from not living in obedience to it. In Ephesians 2:8-10, we are new creation in Christ to do good works, so while we do not earn our salvation by our works lest anyone should boast, doing good works is nevertheless intrinsically part of our salvation from not doing good works. For example, honoring our parents is intrinsically part of Jesus saving us from not honoring our parents. So the fact that we do not earn our salvation by our works as a wage does not mean that our salvation does not require us to choose to do good works for a correct reason.
When a parent gives their child instructions, their primary goal is to teach them how to rightly live, not to reveal to them how bad they are at following instructions. While those instructions will reveal to them how bad they are at following instructions, there would be no point in giving a child instructions for the primary purpose of revealing to them how bad they are at following those instructions. In the same way, the primarily goal of God giving the gift of His law is to teach us how to do what is holy, righteous, and good (Romans 7:12) as well as express other aspects of His nature, while sin is what is against God's nature.