What use is it, my brethren, if someone says he has faith but he has no works? Can that faith save him? James 2:14
The answer to James' rhetorical question is no. When James brings up salvation, he is trying to fix peoples' incorrect thinking which formed from their first hearing of the gospel from Paul. Paul states we are saved by grace through faith alone, but people began using this as justification to continue in sin. James does not want people to believe that they can just have a belief which will save them without a real change in who they are.
This can indeed be a very confusing topic. Our works do not save us, but one without any good works proves he is not truly saved. We must be aware not to begin working for our righteousness, though, because we will stumble if our identity is being put in our own ability instead of in Christ. It is ironic that the very result of having a saving faith, which is our good works, can pull us apart from God when we put them on par with faith as equal. Works are good, but we cannot trust in them, nor should we live a life of legalism because works will become our God. There is a reason God set us free from works as the means to righteousness. It is because He knew we were incapable. In addition, He probably did not want us to serve them as other religions do. He wants us to just serve Him and have works be a natural result of that service.
For I am convinced that neither death, nor life, nor angels, nor principalities, nor things present, nor things to come, nor powers, nor height, nor depth, nor any other created thing, will be able to separate us from the love of God, which is in Christ Jesus our Lord. Romans 8:38-39

When we find that our actions were wrong or our motives were not pure, we should not feel like a total failure. Our identity should not be wrapped up in these works which cannot save us. Our identity is in Christ and His righteousness because He did what we could not out of selfless love. We are forgiven. Although God does expect our faith to prove itself through works, we are no longer chained to these works! We are free to still mess up and be His child. He will not disown us because we continue to sin. He died so we could live free from trying to be perfect. He does not want our main goal to be doing good works because that means we expect those works to save us. He expects us to love Him and walk by faith almost expecting to fail and then to be picked back up again by our Father.
In addition, we should not live in fear of messing up. This will cause us to become apathetic and to take no action at all. Sometimes it is better to prayerfully take action by faith even when we are unsure of the outcome so we can learn. Our constant driving force should be a love for God, which will result in a change in who we are by the Holy Spirit. Works will be a natural by-product. Our constant driving force should not be a love for ourselves which will seek to live righteously for others to see and to feel good about ourselves. This is legalism.