If God wants people to be good, why don’t good works count for getting into Heaven?
To pronounce a guilty man righteous is unjust by itself. God’s mercy would not allow God to leave us to our fate which is eternal separation from Him. His justice demanded punishment for our sin. The only possibility was for God to become man as Jesus and die in our place. His death, not good works, is the only payment for sin He will accept. Believe in Jesus, not your works, and have eternal life.
So it is clear that no one will be made right with God by trying to keep the law (works).