• :GetModel() on Server?
    2 replies, posted
Entity/GetModel The page on the wiki says this works on both Client and Server, but I'm having an error. Very simple at the moment hook.Add( "OnEntityCreated", "ddlSetHealthNoConsole", function( child ); if child:IsNPC() then; local cClass = child:GetClass() local cModel = child:GetModel() print("cModel: "..cModel) end; end ) I plan to revising the health of Citizens based on what their model is; refugee, rebel, or regular citizen. I placed semicolons in the code I pasted on the wiki because without them it was smashing lines together without whitespace. Is this because I'm using Chrome? I'm testing everything in sandbox right now, because I like having access to the menu to find models easily, and not need to use the console to give myself the weapons I make, and so on. Any way, how can I figure this out if Entity/GetModel is printing this to the console: [ERROR] addons/myaddon/lua/autorun/ddl_npc_health_manager.lua:21: attempt to concatenate local 'cModel' (a nil value)   1. v - addons/myaddon/lua/autorun/ddl_npc_health_manager.lua:21    2. unknown - lua/includes/modules/hook.lua:84     3. Create - [C]:-1      4. InternalSpawnNPC - gamemodes/sandbox/gamemode/commands.lua:351       5. Spawn_NPC - gamemodes/sandbox/gamemode/commands.lua:479        6. unknown - gamemodes/sandbox/gamemode/commands.lua:509         7. unknown - lua/includes/modules/concommand.lua:54 ^ That's all blue. It works fine on Client but clearly not on Server. Another note, this is why I loved the old "Questions(problems) that don't need their own thread" thread. This seems like such a simple/small error to create an entire new thread for.
"Invalid NPCs passed through this hook are used by the engine to precache things like models and sounds, so always check their validity with IsValid." Source: GM/OnEntityCreated
Like this, then? (again, semicolons dont really exist in my code. I dont even know how to properly use them tbh) if child:IsNPC() && IsValid(child) then; local cClass = child:GetClass() local cModel = child:GetModel() print("cModel: "..cModel) end
Sorry, you need to Log In to post a reply to this thread.