PrintMessage Error

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

[/lua]
but i get that error:
mdl
[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:

[lua]
entity:SetOwner(player);
[/lua]

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

[editline]13th November 2010[/editline]

And always do a check, e.g:

[lua]
local owner = self:GetOwner();

if ( IsValid(owner) ) then – are we valid?
– print message.
end;
[/lua]

i solved the problem
thx for your help