check whether an object is really a luaentity before trying to get its name

This was crashing consistently for me.