PrintMessage Error

i wrote that function in my entity:
–shows the player that the generator overloads
self.Entity:GetOwner():PrintMessage(HUD_PRINTCENTER,"Generator overloads in: "…self.Countdown)

but i get that error:
[lua\entities\generator\init.lua:58] attempt to call method ‘PrintMessage’ (a nil value)

i don’t know another function that makes the same as “PrintMessage”, but it says it is nil
please help me

:GetOwner() probably returns NULL. It does not return the player who spawned the SENT, you have to set it manually.

ok i defined local owner = ply in that function now but it still says that owner is nil

No, when you create the entity you need to do:


…obviously replacing ‘entity’ and ‘player’ with what you have called them.

[editline]13th November 2010[/editline]

And always do a check, e.g:

local owner = self:GetOwner();

if ( IsValid(owner) ) then – are we valid?
– print message.

i solved the problem
thx for your help