• Why do I get this error? "attempt to call method 'TakeDamage' (a nil value)"
    2 replies, posted
Full errorcode: [code] [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 [/code] The lines in sh_player.lua that gives me the error: [code] 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 [/code] The function is called by GM:Think in shared.lua: [code] function GM:Think() for i, v in ipairs( player.GetAll() ) do if ( v:Alive() ) then v:Bleeding(); //line 125 end end end [/code] Any help apreciated, even just a winking smiley would help a lot! :'( [B]Edit: [/B]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.
[QUOTE=Blasteh;47402838]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.[/QUOTE] Thank you very much!
Sorry, you need to Log In to post a reply to this thread.