Place while(!mainCharacter) wait(1); in line 28 before the first physX instruction. Even though the entities are loaded already, their actions will be run after your first wait(1) in the main function, thus the pointer is invalid when you try to access it.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual