Error when "TakeDamage" is Called when SWEP is used on a Server

When on a multi-player server in Gmod, a lua error occurs whenever my swep is used.
The error in question:

[ERROR] lua/weapons/amandatodd.lua:216: attempt to call method ‘TakeDamage’ (a nil value)

  1. unknown - lua/weapons/amandatodd.lua:216

The code in question:



 if ply:Health() < 11 then 

 		self:EmitSound ( "ambient/water/drip3.wav" ) 
 	timer.Simple ( 2, function() ply:TakeDamage( 10, self, amandatodd ) end ) 
 		timer.Simple ( 1.5, function() self.Owner:EmitSound ( "npc/zombie/zombie_pain1.wav" ) end ) 
 		timer.Simple ( 1.5, function() ParticleEffectAttach( "blood_impact_red_01_goop", PATTACH_POINT_FOLLOW, self.Owner, self.Owner:LookupAttachment("mouth") ) end ) 
 		timer.Simple ( 1.5, function() ParticleEffectAttach( "vomit_barnacle_b", PATTACH_POINT_FOLLOW, self.Owner, self.Owner:LookupAttachment("mouth") ) end ) 
 		timer.Simple( 1, function() self:SendWeaponAnim( ACT_VM_THROW ) end ) 
	
 end 


The code works perfectly in client, and still is functional in servers, but it’s still annoying for the error to pop up. I imagine I’ll have to use “If Server” but I have come to no conclusion. Any ideas on this problem?

P.s First Facepunch post plz don’t bully me :frowning:

p.ss Technically 2nd since posted in the wrong thread

Yes, TakeDamage is serverside, so only call it on the server.

[del]Yes, that works, but what should I use for client side instead of TakeDamage?[/del]

Nevermind, it works now. For anyone who comes to this problem:



if ply:Health() < 11 then
		self:EmitSound ( "ambient/water/drip3.wav" )
		if SERVER
			timer.Simple ( 2, function() ply:TakeDamage( 10, self, amandatodd ) end )
		end
		timer.Simple ( 1.5, function() self.Owner:EmitSound ( "npc/zombie/zombie_pain1.wav" ) end )
		timer.Simple ( 1.5, function() ParticleEffectAttach( "blood_impact_red_01_goop", PATTACH_POINT_FOLLOW, self.Owner, self.Owner:LookupAttachment("mouth") ) end )
		timer.Simple ( 1.5, function() ParticleEffectAttach( "vomit_barnacle_b", PATTACH_POINT_FOLLOW, self.Owner, self.Owner:LookupAttachment("mouth") ) end )
		timer.Simple( 1, function() self:SendWeaponAnim( ACT_VM_THROW ) end )
	
end