**Objective: **I’m trying to destroy my sent when it has lived for 30 seconds but I don’t get what is wrong with my code.
**Error: **Timer Error: entities/sent_raketti/init.lua:23: attempt to index field ‘Entity’ (a nil value)
**Code: ** (I commented line 23) [lua]function ENT:Initialize()
self.Entity:SetModel( "models/items/ar2_grenade.mdl" )
self.Entity:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics,
self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics
self.Entity:SetSolid( SOLID_VPHYSICS )
local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
self.Entity:SpawnTrail()
timer.Simple(30, function()
if (self.Entity:IsValid()) then --THIS IS LINE 23
local parent = self.Entity:GetParent()
if ( parent:IsValid() ) then
parent:Remove()
end
self.Entity:Explode(self.Entity)
self.Entity:Remove()
end
end)
end[/lua]
**Notes: ** The code that’s inside timer works fine in my PhysicsCollide function. I wanted to make sure it’s removed after 30 seconds by making that timer but it’s giving that error after 30 seconds.