Attempt to index local 'self' HELP!

My ERROR:

[ERROR] addons/jakuspl/lua/entities/sent_firerocket/init.lua:34: attempt to index local ‘self’ (a nil value)

  1. Explosion - addons/jakuspl/lua/entities/sent_firerocket/init.lua:34
  2. unknown - addons/jakuspl/lua/entities/sent_firerocket/init.lua:53

My code:

AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( “shared.lua” )

function ENT:Initialize()
self.Entity:SetModel( “models/Weapons/W_missile_closed.mdl” )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:PhysicsInit( MOVETYPE_VPHYSICS )
self.Entity:PhysicsInit( SOLID_VPHYSICS )

 self.PhysObj = self.Entity:GetPhysicsObject()
 if (self.PhysObj:IsValid() ) then
  self.PhysObj = self.Entity:GetPhysicsObject()
  self.PhysObj:EnableGravity( false )
  self.PhysObj:SetMass(45)
  self.PhysObj:Wake()	  
end
  self.Entity:EmitSound( "Missile.Accelerate" )
  
  	
local trail = ents.Create( "env_fire_trail" )
      trail:SetPos( self.Entity:GetPos() )
	  trail:SetParent( self.Entity )
	  trail:Spawn()
	  trail:Activate()

end

function ENT:Explosion()

local fire = ents.Create("env_fire")
      fire:SetPos( self.Entity:GetPos() + Vector( math.random( -200, 200), math.random( -200, 200), 0) )
	  fire:SetKeyValue( "health", math.random( 3, 7 ) )
	  fire:SetKeyValue( "firesize", math.random( 25, 32 ) )
	  fire:SetKeyValue( "fireattack", math.random( 7, 9 ) )
	  fire:SetKeyValue( "damagescale", "2.0" )
	  fire:SetKeyValue( "StartDisabled", "0" )
	  fire:SetKeyValue( "firetype", "0" )
	  fire:SetKeyValue( "spawnflags", "128" )
	  fire:Spawn()
	  fire:Fire( "StartFire", "", 0.2 )
	  end

end

function ENT:OnRemove()
self.Entity:StopSound( "Missile.Accelerate" )
end


function ENT:PhysicsCollide( data, physobj )
self:Entity:EmitSound("explode_4")
self:Explosion()
self:Entity:Remove()
end

self.Entity is deprecated, don’t use it.

The error is from you using self:Entity instead of self.Entity in :PhysicsCollide.

To post code next time, use [noparse]




[/noparse] or [noparse][lua][/lua][/noparse]

Thanks

Instead of self.Entity, use self [ adding this just en case it wasn’t clear ].