Hey guys, I’m fixing up an old gamemode called Cube 2.2 and it all works perfectly fine, apart from a suicide gun which is part of the game. When you have the gun, you kill yourself fine, but there’s a lua error regardless after you’ve died, about TakeDamage being a nil value. The original function this part of the swep was using was SWEP:Shoot, which didn’t allow the gun to fire and caused self in the first self.Owner line to be a nil value, but after some research I learnt why this was and changed it to Think. If this is incorrect, do let me know since I haven’t worked with SWEPs much.
Below is the error and code. I try to avoid making threads like this, but I’ve been reading through a lot of old Facepunch threads and Wiki pages, however none of them have really helped. I have been playing around with the code and changed various things I thought might work, but none of them have. If any of you guys could point out what I’m doing wrong or head me in the right direction, it would be greatly appreciated.
function SWEP:Think() local pos = self.Owner:GetPos(); sound.Play( self.ShootSound, self:GetPos() ); -- So the sound doesn't cut after I die self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ); self.Owner:TakeDamage( 200, self, self ); // this line end