[HELP] Hovering names going through walls.

So im using this name above head script from nucleotic in my gamemode.



function HoveringNames()

	for _, target in pairs(player.GetAll()) do
		if target:Alive() and target != LocalPlayer() then
		
			local targetPos = target:GetPos() + Vector(0,0,84)
			local targetDistance = math.floor((LocalPlayer():GetPos():Distance( targetPos ))/40)
			local targetScreenpos = targetPos:ToScreen()
			draw.SimpleText(target:Nick(), "Trebuchet18", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y), Color(200,25,25,200), TEXT_ALIGN_CENTER)
			
		end
	end
end
hook.Add("HUDPaint", "HoveringNames", HoveringNames)


It goes through walls and I don’t know how to fix it… I believe I would have to use 3d2d text but I don’t really know how to do it.

Also Ik I’m sorry for being a copy/paster

if target:Alive() and target !=LocalPlayer and LocalPlayer():Visible(target) then

Entity:Visible

Visible is serverside only.

Then he should just use 2d3d :^)



local lply
local tpos
local tracedata = {}
local traceres
local minsvec = Vector(-5,-5,-5)
local maxsvec = Vector(5,5,5)

local function LocalPlayerCanSee(ent1)
	if !IsValid(lply) then lply=LocalPlayer() return end
	tpos = ent1.GetShootPos and ent1:GetShootPos() or ent1:GetPos()
	tpos = ( tpos + ent1:GetPos() )/2
	tracedata.start = lply:GetShootPos()
	tracedata.endpos = tpos
	tracedata.mins = minsvec
	tracedata.maxs = maxsvec
	tracedata.filter = { lply, lply:GetActiveWeapon(), ent1.GetActiveWeapon and ent1:GetActiveWeapon() }
	traceres = util.TraceHull(tracedata)
	if traceres.Entity == ent1 then
		return true
	else
		return false
	end
end


You can use this for your visibility check.

So I would do this after that



function HoveringNames()
    if LocalPlayerCanSee = true then
	for _, target in pairs(player.GetAll()) do
		if target:Alive() and target != LocalPlayer() then
		
			local targetPos = target:GetPos() + Vector(0,0,84)
			local targetDistance = math.floor((LocalPlayer():GetPos():Distance( targetPos ))/40)
			local targetScreenpos = targetPos:ToScreen()
			draw.SimpleText(target:Nick(), "Trebuchet18", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y), Color(200,25,25,200), TEXT_ALIGN_CENTER)
			end
		end
	end
end
hook.Add("HUDPaint", "HoveringNames", HoveringNames)


Not quite. LocalPlayerCanSee is a function; it takes an argument of a Player ( or other entity ) and returns if they’re visible. Working code is as such:



local targetPos
local targetScreenpos

local function HoveringNames()

	for _, target in pairs(player.GetAll()) do
		if target:Alive() and target != lply and LocalPlayerCanSee(target) then
		
			targetPos = target:GetShootPos() + Vector(0,0,16)
			targetScreenpos = targetPos:ToScreen()
			draw.SimpleText(target:Nick(), "Trebuchet18", targetScreenpos.x, targetScreenpos.y, Color(200,25,25,200), TEXT_ALIGN_CENTER)
			
		end
	end
end

hook.Add("HUDPaint", "HoveringNames", HoveringNames)


Thx worked like a charm!

Make sure to mark your thread as solved if you don’t need any more help.