When you reconnect, or just connect to the server, it completely stops functioning. I added this to the top, and it messed up the direction of the NPC:
PHP Code:
function onPlayerEnters() {
onCreated();
}
Other than that, excellent job! I really like this.