How to draw text on visible players?

Quick question, how do I check whether a player is visible or not?
I want to draw their name but not if they’re through a wall.


for k, v in pairs (player.GetAll()) do
	local pos = (v:GetPos() + Vector(0, 0, 80)):ToScreen()
		
	if v:IsSuperAdmin() then
		draw.DrawText("[Super Admin] " .. v:Name(), "Trebuchet18", pos.x, pos.y, Color(249, 43, 43), 1)
	elseif v:IsAdmin() then
		draw.DrawText("[Admin] " .. v:Name(), "Trebuchet18", pos.x, pos.y, Color(240, 0, 255), 1)
	else
		draw.DrawText(v:Name(), "Trebuchet18", pos.x, pos.y, Color(10, 143, 171), 1)
	end
end

And by the way i’ve already tried


ToScreen().visible

and it doesn’t work, it’s like completely random and just makes the names flicker.

Why dont you just use

GM/PrePlayerDraw It is called only when a player should be drawn

You’re going to either have to use traces or util.PixelVisible. For traces, you can just trace to each corner of their bounding box until one of the traces doesn’t hit anything or it hits the player, which means that you can see at least part of the player.

Using that hook results in some weird z-fighting issues with translucent and such.