attempt to index global a nil value

Hey there!

I’m working on fixing an addon, but i am getting stumped by this error. I have been able to fix pretty much everything but this. Perhaps you guys can see what is wrong?

[ERROR] lua/autorun/ragdamage.lua:430: attempt to index global ‘attacker’ (a nil value)

  1. v - lua/autorun/ragdamage.lua:430
  2. unknown - lua/includes/modules/hook.lua:82


function FallingNpcTakeDamage( ent, dmginfo )

	for k, v in pairs(ents.GetAll()) do
	if ent.FixShit and ent.FixShit < CurTime() and ent:IsNPC() then
	if GetConVarNumber("sv_npcdamagefall") > 0 and amount >= GetConVarNumber("sv_npcmaxdamageffect") or dmginfo:IsExplosionDamage() and amount >= GetConVarNumber("sv_npcmaxdamageffect") then
	timer.Simple(0.01, function()
	if ent:IsValid() and ent:Health() > 0 then
	 NpcFalling(ent)
	 end
	 end, ent)
	end
	end		
	
	local Body = v:GetNetworkedEntity("NpcFalling")
		if v:GetNWBool("NpcFalling") and Body:IsValid() then 

			if ent != Body then return end
			local dmgtype   = dmginfo:GetDamageType() 
			if attacker:IsWorld() then
			amount1 = ( dmginfo:GetDamage() / GetConVarNumber("sv_npcworlddamagedivider") )
			elseif !attacker:IsWorld() then
			amount1 = dmginfo:GetDamage() 
			end
			local dmgpos 	= dmginfo:GetDamagePosition()
			local dmgtype 	= dmginfo:GetDamageType()
			local norm 		= ent:GetVelocity():GetNormalized()
			
			local CurHealth = v.LastHealth
			local HealthModifier = CurHealth - amount1 
			
			v.LastHealth = math.Clamp(HealthModifier,0,v:GetMaxHealth())
			v:SetHealth(v.LastHealth)
			
			if v.LastHealth > 0 and amount > 15 and NextHurt < CurTime() then
			NextHurt = CurTime() + 0.15
			/*
			if !table.HasValue( CantSound, v:GetClass() ) then
			if ent.Male == true then
			ent:EmitSound(table.Random(MRagdollHurtSound))
			elseif ent.Male == false then
			ent:EmitSound(table.Random(FRagdollHurtSound))
			end
			end
			*/
			if amount > 25 then
			ent:EmitSound(table.Random(BreakBone))
			end
			end
			
			if v.LastHealth <= 0 and v.Died == false then
			v.Died = true
			NpcFallingReset(v)
			end
		
		end
	end

end
hook.Add( "EntityTakeDamage", "FallingNpcTakeDamage", FallingNpcTakeDamage )


Thanks!

Add this:

[lua]local attacker = dmginfo:GetAttacker()[/lua]

after

[lua]local dmgtype = dmginfo:GetDamageType()[/lua]

Fixed it! but now i also get

[ERROR] lua/autorun/ragdamage.lua:446: attempt to compare number with nil

  1. v - lua/autorun/ragdamage.lua:446
  2. unknown - lua/includes/modules/hook.lua:82

bump