The best way to understand is to set an example.

But generally the meaning of this expression is: "fortunately", "luckily", "thankful", "happily" etc. Just like
alby said, the literally translation would be "luck in unluck".
Example:
John: "What happened? You look terrible!
Charles: "My sister got in a car accident."
John: "Oh gosh! Is everything alright? Is she fine?"
Charles: "Yes, yes!
*Fortunately, a random passerby was a doctor who helped her."
*sreća u nesreći
John: "Što se dogodilo? Izgledaš očajno!"
Charles: "Moja je sestra imala prometnu nezgodnu."
Johan : "Ajme ! Je li sve u redu ? Je li dobro?"
Charles: "Da, da! Sreća u nesreći što je slučajan prolaznik bio doktor."
Croatian version of the text above
So, instead of those adverbs as "fortunately", "luckily", "thankful", "happily" it can be used that expression. In Croatian that would be "nasreću" (eng.
luckily – literally translation "on luck").
Generally, it's used when we have two actions:
- the first one is harmful/bad etc.
- the second one reduces the negative effect of the first.
Hope this helps!
