How do I make an entity remove itself after 10 seconds?

I’m working on a requested project and I ran into a snag:
How do I make the entity remove itself after 10 seconds?
I tried using this:
[lua]
function enddummy()
Ent:Remove()
end
[/lua]
And then in the spawn function I did this:
[lua]
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local ent = ents.Create(“ent_poop”)
ent:SetMaterial(“models/shiny”) --This works
ent:SetColor(63,60,60,140) --This works too
ent:SetPos( tr.HitPos + tr.HitNormal * 16 )
ent:Spawn()
ent:Activate()
timer.Simple( 1, enddummy ) --This is where I get an error

return ent

end
[/lua]

My error is:


Timer Error: entities/ent_poop/init.lua:73: attempt to index global 'Ent' (a nil value)

Anyone know a fix to this? :wookie:

[lua]timer.Simple( 10, function()
if IsValid( self ) then
self:Remove()
end
end )[/lua]

As an alternative:

[lua]
function ENT:Initialize()
–some other code
self:Fire(“kill”, “”, 10)
end
[/lua]

But given the choice I’d probably do blackops’ solution. Seems better.

This doesn’t work. :frown:

Are you using a function that has the format ENT:xyz()?

I used
[lua]
timer.Simple( 10, function()
if IsValid( self ) then
self:Remove()
end
end )
[/lua]
And it just didn’t do anything.
Now I’m just trying to use
[lua]
function ENT:Use(activator)
self.Entity:Remove()
end
[/lua]
And that doesn’t even work :confused:
I’m putting it in the init.lua, where it should go.

The function doesn’t know what self is. Put this in your initialise or spawn function.

[lua]

timer.Simple( 1, function()
self.Entity:Remove()
end )

[/lua]

Why not use an already existing function:

[lua]SafeRemoveEntityDelayed( self, 10 );[/lua]

You can’t code for shit.

I agree, but I wouldn’t have put it so harshly.

Lol, thanks guys :frowning: In my defense I only started learning coding around one month ago. WIth lua being my first language.

So don’t try to help unless you’re more advanced.

Ok then, what is so bad with that code I posted?

Most people would be far past the stage of making trivial syntax errors in Lua a month in from learning.

[editline]07:31PM[/editline]

Trivial syntax errors.

At least he’s trying to learn :j: