Self-righteousness or self-reliance or trusting in ones good works appears enticing but its danger is it avoids or negates reliance or dependence on the righteousness of Jesus Christ. There's a big difference. Let's look at these.
There was a time in my life when though I am aware of my sinful mind, i thought i am righteous because i have not done anything that will put me to jail.
Before I read the Bible I thought I am ok. I was unaware of the standard of God.
I got even surprised when I read that heaven or salvation is a gift. A free gift not of works lest anyone should boast.
Perhaps you the readers are asking, " Is it not God loves righteous or good people"? and the answer to that is yes but at what standard ?
God revealed to Jewish people, to Abraham, Moses, Joshua, David etc. His laws and commands. The history of the Jews through their kingdoms and life showed failure to follow God's standard.The Apostle Paul formerly a self righteous Pharisee thought he made it on his own and persecuted the early followers of Jesus.
Things changed when Jesus appeared to Paul ( formerly called Saul of Tarsus) on his way to Damascus in his pursuit of Christians. Then through the years Paul learned and preached righteousness through Jesus Christ.
What is this " righteousnes through Jesus Christ"? In this Jesus Himself took our sins and paid for them Himself on the cross. He gave His righteousness to us. Our old life which has the tendency to sin is replaced with a new life through faith in Jesus Christ,that is when we realized that we have sinned followed by repentance and believing in Jesus Christ as atoning sacrifice or the Lamb of God who takes away the sins of the world.
Another way of looking at this is Jesus is our visa or passport to heaven.
Believing and relying on Jesus opens the giving of God's Holy Spirit to us and meet God's standard of rightousness and holiness.