• attempt to index global 'ply' (a nil value)
    7 replies, posted
I'm pretty much done with a weapon I'm making, but I keep on getting this error: [lua] addons\pee\lua\weapons\weapon_pee\shared.lua:52: attempt to index global 'pl' (a nil value) [/lua] Heres the code for what it is in. I haven't coded in a long time so it may have problems. [lua]function SWEP:PrimaryAttack() local fx = EffectData() ply:GetPos() Vector(0,0,20) util.Effect("pee",fx) end[/lua] Any help on how to fix it? Did i put in the code wrong?
What line is 52 because I dont see pl anywhere in the code you posted
[lua]function SWEP:PrimaryAttack() local fx = EffectData() ply:GetPos() -- Ply doesn't exist, and you're not assigning it to anything Vector(0,0,20) -- Again, not assigning it to anything. util.Effect("pee",fx) end[/lua] I assume this was what you were trying to achieve, don't just copy-pasta it, try to understand it: [lua]function SWEP:PrimaryAttack() local fx = EffectData() fx:SetOrigin(self:GetOwner():GetPos() + Vector(0,0,20)) util.Effect("pee",fx) end[/lua] Whether or not SetOrigin will work of course depends on the effect.
[QUOTE=TechedRonan;22858076][lua]function SWEP:PrimaryAttack() local fx = EffectData() ply:GetPos() -- Ply doesn't exist, and you're not assigning it to anything Vector(0,0,20) -- Again, not assigning it to anything. util.Effect("pee",fx) end[/lua] I assume this was what you were trying to achieve, don't just copy-pasta it, try to understand it: [lua]function SWEP:PrimaryAttack() local fx = EffectData() fx:SetOrigin(self:GetOwner():GetPos() + Vector(0,0,20)) util.Effect("pee",fx) end[/lua] Whether or not SetOrigin will work of course depends on the effect.[/QUOTE] Thanks for that, I'll try it out. I'm not good with origins and all that, so i needed some help and i didn't quite understand it well.
The main problem is that you were calling ply, yet in a SWEP, the player is self:GetOwner(). Creating an effect like you started with would create it 20 units high on the Z axis from the origin of the map.
I thought it was self.Owner:raise:
^ That. self.Owner and self.Weapon are very useful variables in a SWEP.
self.Weapon is deprecated, use self.
Sorry, you need to Log In to post a reply to this thread.