Text above Entity problem

Hey Guys,
I want to show a text above an Entity when Player is looking on it and the text is following then Player.

This is the Code:



function ENT:Think()
	local eye = LocalPlayer():GetEyeTrace()

	if eye.Entity:GetClass() == "ENTITY-NAME" then
	cam.Start3D2D(eye.Entity:GetPos()+Vector(0,0,80),eye.Entity:GetAngles()+Angle(0,90,90),0.1) 

		draw.DrawText("TEXT","1",-70,0,Color(0,0,0),0)

	cam.End3D2D()
	end

end


There is no error in console, but i cant see the Text above the entity.

Use

ENT:Draw instead of ENT:Think. ENT:Think is only ran around 5 times per second by default, not every frame. Plus, as a general rule, you should really always be drawing in a hook meant for drawing. Make sure to check that the entity from the trace is valid using

IsValid before calling any methods on it. Make sure that you draw the model in ENT:Draw too using

Entity:DrawModel.

Yes, but i want the text facing the payer when he’s moving and ENT:Draw just ran 1 time(on Entity Spawn)

ENT:Draw works… whenever something is being Drawn… not just 1 time.

Is the code wrong? I put the code in the ENT:Draw function and it is still not working.

Have you put it in a clientside file?

sure


function ENT:Draw()
	local eye = LocalPlayer():GetEyeTrace()

	if eye.Entity:GetClass() == self:GetClass()   then
	cam.Start3D2D(eye.Entity:GetPos()+Vector(0,0,80),eye.Entity:GetAngles()+Angle(0,90,90),0.1) 

		draw.DrawText("TEXT","1",-70,0,Color(0,0,0),0)

	cam.End3D2D()
	end

end

try this one

Yup i got it already, but use eye.Entity:GetPos() == self:GetPos()
else it would show the text on both if you spawn 2 of them ^^


if eye.Entity == self then ...

Compare the entity. Not its position or class.

The less steps you take, the faster the code run. Don’t add unnecessary steps as that can make your code unmanageable.

Besides, eye.Entity might not return an entity. (If you aim at the sky or something).
It will cause an error if you use :GetClass or :GetPos with no entity.