ため(に)・ように: the difference
ため(に)N3
Meaning
For, For the sake of, In order to
Past papers
Tested 7 times in past papers
Example
家を買うためにローンを組んだ。
I took a loan in order to buy a house.
ようにN4
Meaning
So that, In order to, In such a way that
Past papers
Tested 6 times in past papers
Example
例えば風邪を引かないように、暖かい服装をする。
For example, I wear warm clothes so that I won't catch a cold.
How to tell them apart
Before 「ために」 comes a verb of will (「買うために」), and both parts need the same subject.
Before 「ように」 come non-volitional verbs, potential forms or negatives: 「合格できるように」, 「風邪を引かないように」. The subjects may differ: 「子供が読めるように、平仮名で書いた」 (I wrote it in hiragana so the child could read it).