During the resulting suffering that Job underwent, four friends came along, and three of them tried to convince Job that he had done something wrong. Job kept claiming that he hadn't done anything wrong, but that God was doing wrong by him.
Eventually the fourth friend, Elihu, spoke up, and said that the first three, although older and presumably wiser, were not wise, and he spoke his peace.
Finally, God Himself spoke, and castigated Job for thinking he was oh-so-righteous and knew better than God did, but that Job was right, he hadn't done anything wrong to deserve the suffering. God also forced the first three friends to apologize (via sacrifice), saying He was angry with the three friends. But He spoke nothing of the fourth friend who spoke last, which is interesting, because of what was said about the fourth friend just before he began his speech:
HCSB Job 32:2 Then Elihu son of Barachel the Buzite from the family of Ram became angry. He was angry at Job because he had justified himself rather than God.Job did everything right, but what got him into trouble with God (or at least Elihu) is that Job justified himself by his right-doing, rather than giving the credit to God.
Genesis 6:22 says that "Noah did everything exactly as God had commanded him", but that's not what saved him and his family. Instead, "By his faith Noah ... received the righteousness that comes by faith" (Heb 11:7 NLT).
Don't trust in your own right-ness. Instead, have faith that the right-ness of Yahshua is given to you by God's grace, and then do the right thing.