Moroccan law is generally open to foreign investment. Foreign investors are welcome and public authorities ready to assist. However, it is very important to fulfil formal requirements. Certifications, legalisations, stamps, precise data etc. are taken seriously, and if not observed, the process of setting up or any other later procedure can be delayed.
Moreover, while not necessary from a legal point of view, it is recommendable to have a person on the ground who is well-versed with local customs, has his/her networks in the sector, and speaks the local languages. There are excellent professionals on the ground, often with international experience, but you must choose well.
Strictly (!) complying with the foreign exchange (FX) obligations is another sensitive issue, often neglected by foreigners. If you do, getting capital back out the expatriating dividends is easy. If not and can be a nightmare and delay expatriation of funds for years.
Litigation before the Moroccan courts should be avoided. If possible, and if viable economically, chose arbitration from the outset of a contractual relationship.
Be patient. Some things take longer in Morocco, but this is not the Wild West. The country has managed an enormous leap forward in many areas in the past 10 years. Some important preconditions for a competitive economy are still lagging behind, but the government is undertaking notable efforts to tackle those issues.
Foreign investors should also be aware of three red lines: The King, Islam and the Territory should not be questioned or ridiculed. Both for the government and for most people, those are three important pillars of identity which people expect visitors to respect.