3d2d text that only shows over specific people

So I have no problem making 3d2d text show over entities and people but my problem is that I can’t make it show over only some people’s heads for everyone to see.
My goal is to basically have it write “AFK” over someone’s head when they go afk (v.afk == true).

Some help would really be appreciated.

Thanks!



if CLIENT then
surface.CreateFont( "afkOverheadFont", {
 font = "Bebas Neue",
 size = 80
} )

afk = {}

afk.OverheadTextColor = Color( 255, 255, 255, 255 )
afk.RotateOverheadSpeed = 15
afk.RotateOverheadText = true
afk.BounceOverheadText = true

local function DrawAFK()
	for k,v in pairs(player.GetAll()) do
		if v.afk == true then
			afk.OverheadText = "AFK"
		else
			afk.OverheadText = ""
		end
		local p
		
		if afk.BounceOverheadText then
			p = v:GetPos() + Vector(0,0,90 + math.sin(CurTime()*3)*5)
		else
			p = v:GetPos() + Vector(0,0,90)
		end
		
	
		for _,yaw in pairs({0, 180}) do
	
			local a = Angle(0, 0, 0)
			a:RotateAroundAxis(a:Forward(), 90)
			a:RotateAroundAxis(a:Right(), yaw)
			if afk.RotateOverheadText then
				a:RotateAroundAxis(a:Right(), CurTime() * afk.RotateOverheadSpeed)
			else
				a:RotateAroundAxis(a:Right(), 90)
			end
		
			render.PushFilterMag(TEXFILTER.ANISOTROPIC)
			render.PushFilterMin(TEXFILTER.ANISOTROPIC)
			cam.Start3D2D(p, a, 0.3)
				draw.DrawText(afk.OverheadText, "afkOverheadFont", 0, -100, afk.OverheadTextColor or Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
			cam.End3D2D()
			render.PopFilterMag()
			render.PopFilterMin()
		end
	end
end
hook.Add( "PostDrawOpaqueRenderables", "DrawAFKoverHEAD", DrawAFK )
end


Are you checking to make sure that value is actually set when you’re trying to check for it?
Using regular player table variables like that doesn’t always transfer over or network how you think it might. Check to see the current value of that data member when you’re calling it to ensure it’s accurate. Other than that your code should be correct.

*side note: you don’t need to say “if value == true then” - it’s redundant. You can simply state “if value then”.

Yeah I was having problem where v.afk didn’t actually do anything and it always ends up taking the “else” option. Do you know how I could actually make that work by setting something else where it sets v.afk = true in the afk script?

You shouldn’t be setting an empty string over their head if they aren’t afk.

Yeah I’ll fix that. Also found out how to do this with settings network bool. Thanks everyone!