I have translated "for them" into "til dem" instead of "for dem". I just want to know if there is a way to understand when to use one preposition instead of the other.
Nope, I don't think so. Prepositions are one of the toughest parts of learning a new language, usually rather unpredictable, but also rather important for really understanding a language. :-) Experience is what you need. :-)
So we just take it as it is.