SNPC Spawn Code Not Working

For some reason this code doesn’t work. It doesn’t even print the message, even if I use lua_openscript
And there are no errors printed either.

function SpawnHatLady()
if SERVER then
if ( string.find( string.lower( game.GetMap() ), “colz_” ) ) then
–Lol, no code for this yet :open_mouth:
elseif ( string.lower( game.GetMap() ) == “rp_downtown_v2” ) then
–setpos -2862.375000 -1985.343750 -49.875000;setang -1.381697 0.827408 0.000000

                    local hatlady = ents.Create( "snpc_hatlady" )
                    hatlady:SetPos( Vector(-2862.375000,-1985.343750,-49.875000) )
                    hatlady:SetAngles( Angle(-1.381697,0.827408,0.000000) )
					for k,v in pairs(player.GetAll()) do
						print("well.. your Hat Lady has spawned. :O")
					for k,v in pairs(player.GetAll()) do
						print("FATAL ERROR: Invalid Map")

hook.Add( “InitPostEntity”, “SpawnHatLady”, SpawnHatLady )

Is you use this code with lua_openscript it obviously won’t do anything since all it does is add a hook to an event that won’t occur again. Have you tried running the code out of the hook to test it? Are you sure snpc_hatlady can be spawned normally without errors?

Yes I am sure because I have spawned the hatlady before. And two I have tried running the code without the hook. And Quebecer, please go on steam so we can talk about this.

Just dissect your code to see what doesn’t work. It’s not really difficult. If the spawning code on it’s own works then check the conditions. If they work too then it’s the hook. If it isn’t maybe the file isn’t even properly loaded.