Entities not spawning


function SWEP:PrimaryAttack()

     timer.Simple(0.9, self.PrimaryFire, self)
self.Weapon:EmitSound("weapons/punch/falcon_punch(2).wav")
self.Weapon:SetNextPrimaryFire(CurTime() + 0.9)

 end

function SWEP:PrimaryFire()

self.Weapon:SetNextPrimaryFire(CurTime() + 0.9)

local trace = self.Owner:GetEyeTrace()

if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 then
   trace.Entity:Ignite(3,1)
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
    bullet = {}
    bullet.Num    = 5
    bullet.Src    = self.Owner:GetShootPos()
    bullet.Dir    = self.Owner:GetAimVector()
    bullet.Spread = Vector(0.1, 0, 0.1)
    bullet.Tracer = 1
    bullet.Force  = 9999
    bullet.Damage = 5000
   trace.Entity:Ignite(3,1)
trace.Entity:Ignite(3,1)
self.Owner:FireBullets(bullet)
trace.Entity:Ignite(3,1)
self.Owner:SetAnimation( PLAYER_ATTACK1 );
trace.Entity:Ignite(3,1)
trace.Entity:Ignite(3,1)
***local explosion = ents.Create( "env_explosion" )
explosion:SetPos(trace.HitPos)
explosion:SetKeyValue( "iMagnitude" , "150" )
explosion:SetPhysicsAttacker(owner)
explosion:SetOwner(owner)
explosion:Spawn()
explosion:Fire("explode","",0)
explosion:Fire("kill","",0 )***
self.Weapon:EmitSound("weapons/mortar/mortar_explode2.wav")



else
    self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
self.Owner:SetAnimation( PLAYER_ATTACK1 )
end
end

That’s the primary attack code of my swep. All of this are punch codes, and all of them works fine.

But I’m trying to create a explosion when i punch. I made this code:

local explosion = ents.Create( “env_explosion” )
explosion:SetPos(trace.HitPos)
explosion:SetKeyValue( “iMagnitude” , “150” )
explosion:SetPhysicsAttacker(owner)
explosion:SetOwner(owner)
explosion:Spawn()
explosion:Fire(“explode”,"",0)
explosion:Fire(“kill”,"",0 )

But nothing happens. It doesn’t spawn any explosion… Tried placing it everywhere, Can someone tell me why doesn’t it work? :confused:

I tried placing it everywhere inside the primary attack code. But nothing happens…


explosion:SetPhysicsAttacker(owner)
explosion:SetOwner(owner)

In the code snippet you’ve given us self.Owner is defined, but owner is not. If that was your problem maybe you should check your console for errors next time. :smile:

There’s nothing on the console, that’s the problem.

If you’re testing on a dedicated server you won’t be able to see the server lua errors. Make sure to test in singleplayer too. But first check, was owner defined? Because that would be a problem if it wasn’t :).

I have barely worked with effects so I’m not sure but maybe because you are instantly killing your explosion.
explosion:Fire(“kill”,"",0 )

Nah that’s fine. Depending on it’s config it can even remove itself.

I have set the owner to “self.owner” (is this correct?) but it still don’t spawn it.

Made it work. But now the explosion is killing me. Is there a way to make it not deal damage?

EDIT: nevermind, made it stop killing me (i don’t know how)