Got a "a nil value" problem

Whats my problem here?

function ENT:Think()
ply = self.Entity:GetNetworkedString("Owner")

	ply:SendHint("Resource in water will get removed in 20sec", 5)

Error is
attempt to call method ‘SendHint’ (a nil value)

i try many thing to get it to work…
Im sure it just some thing stupid i forgot…

ply is a string and you are trying to call a method on it.


What is the networked string ‘Owner’? Is it the players name, steammid, entindex?

will be players name

Then you need to grab the player object from the name, you can do that like this:

[lua]local function GetPlayerFromName(n)
for _, p in ipairs(player.GetAll()) do
if p:Nick() == n then
return p


Then you can use it in your code:

[lua]function ENT:Think()
local ply = GetPlayerFromName(self.Entity:GetNetworkedString(“Owner”))
if ValidEntity(ply) then
ply:SendHint(“Resource in water will get removed in 20sec”, 5)

Got it working… kinda… SendHint wont work…

That means ply isn’t valid, which means there is no player by the name contained in :GetNetworkedString(“Owner”)

That’s a bit silly. Instead you should change the NetworkedString into a NetworkedEntity, it would save everyone a lot of trouble and would account for the owner changing his name.

Definitely much better then looping through all players each think.

Networking entities would probably be more efficient than networking integers though. I prefer storing the entity’s index in an integer and then just referencing the entity using the Entity(int) function.

I’m pretty sure a networked entity is just that, a single integer. So there isn’t much gain from doing that.

Yea I know, I was helping him with his problem, not suggesting ways around it.