Entity Isuues



local ZombieSpawn = ents.FindByName("ZombieSpawn"):GetPos()
PrintMessage(HUD_PRINTTALK, ZombieSpawn)


[ERROR] lua/print.lua:1: attempt to call method ‘GetPos’ (a nil value)

  1. unknown - lua/print.lua:1

Any ideas?

Either
a) It’s returning a table of all of the “ZombieSpawn”'s
b) There are no “ZombieSpawn”'s
c) You’re retrieving an entity with no GetPos function(least likely)

try this in console:
lua_run Msg(tostring(ents.FindByName(“ZombieSpawn”))
If it returns nil, then it’s b
If it returns a table, then its a and you need to find the specific one out of the table
If anything else, it’s probably c

Okay I know there’s a Zombie Spawn, and there is only one.

Try this:



local ZombieSpawns = ents.FindByName( "ZombieSpawn" )
for _,value in pairs( ZombieSpawns ) do
	PrintMessage( HUD_PRINTTALK, tostring( value:GetPos() ) )
end


dont know it works, didnt test it.
as far as i know the FindByName returns a table.

Is there a way to just get one thing by name? That also worked…

well yes thats possible aswell,

Id suggest you read something about tables,
you might want to try this:



local ZombieSpawn = ents.FindByName( "ZombieSpawn" )
PrintMessage( HUD_PRINTTALK, tostring( ZombieSpawn[1]:GetPos() ) )


the ‘[1]’ specifies the key of the listed value.

Well I know how to use tables, it’s just i’m new to gmod’s lua. But thanks, really helped.

Anytime.