A SWEP to minus players health?

I’m making a small custom SWEP for a fairly useless mini-project of mine, and this is what I have.

[lua]function SWEP:PrimaryAttack()

local tr = self.Owner:GetEyeTrace().Entity
if not tr:IsValid() then return end
if tr:IsPlayer() then else return end
if tr:GetPos():Distance( self.Owner:GetPos() ) > self.Primary.Distance then return end
if SERVER then
	self.Owner:EmitSound( self.Primary.Sound, 75, 160 )
	tr:SetHealth( tr:Health - 5 ) --Damages Player for 5 HP


I’m trying to make it so that when a player is within distance in eyetrace, it removes 5HP and plays a sound.

**Problem 1:**The sound works but it refuses to make the victim’s HP minus 5.
**Problem 2:**How can I go about making a small ‘nudge’ effect you see on other SWEPs, where the victim takes pain and it nudges him a little in the opposite direction?

Thanks in advance for any help/info guys, I appreciate it.


It’s a function, you forgot the () to get the player’s initial health.

Thank you, it now takes 5 HP every time a player is clicked!

However, at 5HP it sets HP to 0 and the player doesn’t die. Any way to make it DAMAGE the player rather than just setting HP?

[editline]31st January 2013[/editline]

Fixed it.

Replace: tr:SetHealth( tr:SetHealth() -5 )
With: ply:TakeDamage (5)

Yeah, but to help you anyways you would of put this after the player takes damage:

if ply:Health() <= 0 then ply:Kill() end