• Swep to only damage a npc
    3 replies, posted
Trying to create a swep that only damages a npc and not players so far i came up with this but doesnt work hook.Add("EntityTakeDamage","gunNoDmg",function(target,dmg) local ply = dmg:GetAttacker() if(target:IsPlayer())then  if(IsValid(ply:GetActiveWeapon()) and ply:GetActiveWeapon():GetClass() == "huntrif")then dmg:SetDamage(0) end end end) idk why code box seems to mess up code hook.Add("EntityTakeDamage","gunNoDmg",function(target,dmg) local ply = dmg:GetAttacker() if(target:IsPlayer())then  if(IsValid(ply:GetActiveWeapon()) and ply:GetActiveWeapon():GetClass() == "huntrif")then dmg:SetDamage(0) end end end)
Do you run it serverside?
yeah i throw it in a if (SERVER)
Is the dmg:GetAttacker() valid?
Sorry, you need to Log In to post a reply to this thread.