In line of sight

Hello! I’ve been searching for a script that return true if a player can see a entity. Ent:Visible( target ) does not work at all for some reason, since it was return false when i could see it.

I then i tried this one, but it’s not reliable:



local tracedata = {}
    tracedata.start = LocalPlayer():EyePos()
    tracedata.endpos = obj:GetPos() + Vector(0, 0, 32)
    tracedata.filter = LocalPlayer()
    local trace = util.TraceLine(tracedata)
    if trace.Entity:IsWorld() then
        return false
    else
        return true
    end
end


Any suggestions?

Try doing trace.Entity:IsValid()

Why not just if trace.Hit and trace.Entity

tracedata = {}
tracedata.start = LocalPlayer():EyePos()
tracedata.endpos = obj:GetPos() + Vector(0, 0, 32)
tracedata.filter = LocalPlayer()
local trace = util.TraceLine(tracedata)
if trace.Entity:IsValid() then
return ture
else
return false
end

Rushed it, might not work