• Lightsaber help!
    3 replies, posted
I'm very new to this lua coding and I'm reading that theres an error in an addon i have for my server this is the error [CODE][ERROR] addons/lightsaber/lua/weapons/lightsaber/shared.lua:144: attempt to index local 'self' (a nil value) 1. unknown - addons/lightsaber/lua/weapons/lightsaber/shared.lua:144 Timer Failed! [Simple][@addons/lightsaber/lua/weapons/lightsaber/shared.lua (line 140)][/CODE] this is the shared.lua file [CODE]/*--------------------------------------------------------- SecondaryAttack ---------------------------------------------------------*/ SWEP.InAirDmg = 0 function SWEP:SecondaryAttack() if SERVER then self.Owner:EmitSound(Sound("ls/lightsaber_swing"..tostring(math.random(2,3))..".wav")) end if SERVER then self.Owner:EmitSound(Sound("player/suit_sprint.wav")) end self.Weapon:SetNextSecondaryFire(CurTime() + 100) self.Weapon:SetNextPrimaryFire(CurTime() + 100) self.PrevHP = self.Owner:Health() if SERVER then self.Owner:SetVelocity(self.Owner:GetForward() * 400 + Vector(0,0,400)) end timer.Simple(0.2,self.SecondaryAttackDelay,self) end function SWEP:SecondaryAttackDelay() self.InAirDmg = 1 self.JumpRefire = true end[/CODE]
Change this [CODE]timer.Simple(0.2,self.SecondaryAttackDelay,self)[/CODE] to [CODE] timer.Simple(0.2, function() if self and IsValid(self) then self:SecondaryAttackDelay() end end)[/CODE] Everytime you use timer in swep/entity code, you need to check if entity is still valid.
[QUOTE=krekeris;48375273]Change this [CODE]timer.Simple(0.2,self.SecondaryAttackDelay,self)[/CODE] to [CODE] timer.Simple(0.2, function() if self and IsValid(self) then self:SecondaryAttackDelay() end end)[/CODE] Everytime you use timer in swep/entity code, you need to check if entity is still valid.[/QUOTE] Thanks so much dude! :D But is there a way to be able to use the secondary attack again while in mid air?
This might help. [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/IsOnGround]Entity:IsOnGround[/url]
Sorry, you need to Log In to post a reply to this thread.