I am trying to create a gun that kills the user upon firing, most of the stuff I want works except the kill part
The code section in question:
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
self:TakePrimaryAmmo( 1 )
self.Weapon:EmitSound( "Weapon_Pistoĺ.Single" )
self:ShootBullet( 0, 1, 0.01 )
self.Owner:ViewPunch( Angle( -1, 0, 0 ) )
if SERVER then
self.Owner:StripWeapon("weapon_ttt_test")
self.Owner:Kill();
end
end
and the error:
[ERROR] addons/testmodpleaseignore/gamemodes/terrortown/entities/weapons/weapon_ttt_test.lua:60: attempt to call method 'Kill' (a nil value)
1. unknown - addons/testmodpleaseignore/gamemodes/terrortown/entities/weapons/weapon_ttt_test.lua:60
EDIT: Solved it
function SWEP:PrimaryAttack()
var = self.Owner
print(var)
if ( !self:CanPrimaryAttack() ) then return end
self:TakePrimaryAmmo( 1 )
self.Weapon:EmitSound( "Weapon_Pistoĺ.Single" )
self:ShootBullet( 0, 1, 0.01 )
self.Owner:ViewPunch( Angle( -1, 0, 0 ) )
if SERVER then
var:StripWeapon("weapon_ttt_test")
var:Kill();
end
end