Tried to use a NULL entity; though it's not a null entity.

[lua]function GM:PlayerTrailSet(pl,mat,r,g,b)
if pl:IsVIP() then
if not pl.Trail then
pl.Trail = ents.Create(“ent_player_trail”)
pl.Trail:SetOwner(pl)
pl.Trail:Spawn()
pl.Trail:SetTrail(mat,r,g,b)
pl.Trail:SetPos(pl:GetPos()+Vector(0,0,25))
pl.Trail:SetParent(pl)
elseif pl.Trail then
if pl.Trail:GetClass() == “ent_player_trail” then
pl.Trail:SetTrail(mat,r,g,b)
end
end
end
end[/lua]

Line 11 returns error: Tried to use a NULL entity!
This doesn’t make sense because I made an extra ‘elseif then’ to check if the entity is null or not. I even tried ‘pl.Trail != nil’ but that also failed to work. It works the first time but when updating the trail it jumps to the elseif since the player already has the trail entity.

[lua]
function GM:PlayerSetTrail(p, m, r, g, b)
if( p:IsVIP() ) then
if not( p.Trail && IsValid(p.Trail) ) then
p.Trail = util.SpriteTrail(p, 0, Color(r, g, b), false, 15, 1, 2, 1/16*0.5, m)
end
end
end
[/lua]

IsValid does nil check for you, just thought I’d let you know:rolleyes:

I’ll try using IsValid to fix this.

@Averice I’m not using SpriteTrails, it’s a SENT (Note the unique name).

for line 10 in that example try

elseif ValidEntity(pl.Trail) then

It’s a convenience function, the equivalent of doing

if ent and ent:IsValid()

To avoid any potential confusion, ValidEntity and IsValid is the same function

However IsValid is not to confuse with the meta function Entity.IsValid