Checking if a NPC is alive

Im making a script to tag an npc with a sprite and it works but when they die the sprite floats there for a second disappears and the script crashes. here is the code
[lua]
local dodraw = false
local pos,material,white = target:GetPos(), Material( “sprites/splodesprite” ),Color(255,255,255,255)
hook.Add( “HUDPaint”, “paintsprites”, function()

if ( input.IsMouseDown( MOUSE_RIGHT ) ) then
dodraw=true
target = LocalPlayer():GetEyeTrace().Entity 
end

if(dodraw)then
if(target.IsNPC() and )then 
cam.Start3D(EyePos(),EyeAngles())  
render.SetMaterial(material )  
render.DrawSprite( target:GetPos()+(angles:Up()*100), 16, 16, white)  
cam.End3D()
else
dodraw = false
end

end
end)

[/lua]

Your problem is line 12, that’s not even valid code.
Try
[lua]if (IsValid(target) and target:IsNPC()) then[/lua]
Also, format your code so it’s actually readable, what you’ve done is horrible.

[editline]12:19AM[/editline]

You have a very large number of threads. You should make one called “??? doesn’t know how to do what he’s doing” and ask each question in there sequentially, rather than making a new thread every five seconds.

it’s not every five seconds its as i come across problems with things, and thanks for the help.

Regardless of how fast you’re making them, you’re still making a lot, and you’re welcome.