Why do I get this error? "attempt to call method 'TakeDamage' (a nil value)"

Full errorcode:



[ERROR] gamemodes/projectbic/gamemode/sh_player.lua:95: attempt to call method 'TakeDamage' (a nil value)
  1. Bleeding - gamemodes/projectbic/gamemode/sh_player.lua:95
   2. unknown - gamemodes/projectbic/gamemode/shared.lua:125


The lines in sh_player.lua that gives me the error:



local plyMeta = FindMetaTable( "Player" );
function plyMeta:Bleeding()
	local timeSinceLastDrop = timeSinceLastDrop || 0;
	if ( CurTime() > timeSinceLastDrop + 0.1 ) then
		timeSinceLastDrop = CurTime();
		self:TakeDamage( 0.1 ); //line 95
	end
end


The function is called by GM:Think in shared.lua:



function GM:Think()
	for i, v in ipairs( player.GetAll() ) do
		if ( v:Alive() ) then
			v:Bleeding(); //line 125
		end
	end
end


Any help apreciated, even just a winking smiley would help a lot! :’(

**Edit: **I should mention that everything seems to work fine, the player takes the damage. I just get a lot of errors in the console.

Probably because the code is being called both server and client side? surround the Bleeding() function with [lua]
if SERVER then
– code …
end[/lua]

also you’ve put a local in that function, which means your check will always be
[lua]if CurTime() > 0 + 0.1 then …[/lua]

use self.timeSinceLastDrop instead.

Thank you very much!