That's because "onCreated" serversided in a local NPC isn't an event triggered related to a player, so "player" equals NULL.
You'll need to pass the player object through your putnpc function, similar to this:
PHP Code:
temp.foobar = putnpc2(x, y, "");
foobar.owner = player;
Then you can just replace "player" with "this.owner" in the script.