evasivedocs
Roblox scriptingLuau 0.748 · 24 guides · 385 API entries
Examples

Tracers with a visibility check

A line from the bottom of your screen to every other player's feet. The line is green when a ray from the camera reaches the player's head without hitting a wall, and grey when something is in the way.

The raycast filter leaves out your own character, so your body never blocks the check. See Raycasting for what a ray can and cannot hit.

Luau
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer

local SEEN = Color3.fromRGB(80, 255, 120)
local HIDDEN = Color3.fromRGB(150, 150, 150)

local lines = {}
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude

local function canSee(character, head, origin)
    local hit = workspace:Raycast(origin, head.Position - origin, params)
    return hit == nil or hit.Instance:IsDescendantOf(character)
end

RunService.RenderStepped:Connect(function()
    local camera = workspace.CurrentCamera
    local origin = camera.Position
    local size = camera.ViewportSize
    local from = Vector2.new(size.X / 2, size.Y)
    params.FilterDescendantsInstances = { LocalPlayer.Character }

    local present = {}
    for _, player in ipairs(Players:GetPlayers()) do
        if player ~= LocalPlayer then
            present[player] = true
            local line = lines[player]
            if not line then
                line = Drawing.new("Line")
                line.Thickness = 1.5
                lines[player] = line
            end

            local character = player.Character
            local root = character and character:FindFirstChild("HumanoidRootPart")
            local head = character and character:FindFirstChild("Head")
            local feet, onScreen
            if root and head then
                feet, onScreen = WorldToScreen(root.Position - Vector3.new(0, 3, 0))
            end

            if onScreen then
                line.From = from
                line.To = feet
                line.Color = canSee(character, head, origin) and SEEN or HIDDEN
                line.Visible = true
            else
                line.Visible = false
            end
        end
    end

    for player, line in pairs(lines) do
        if not present[player] then
            line:Remove()
            lines[player] = nil
        end
    end
end)

Things to change

  • Start the lines at the centre of the screen with Vector2.new(size.X / 2, size.Y / 2), or at the cursor with game:GetService("UserInputService"):GetMouseLocation().
  • Hide hidden players completely by setting line.Visible to the result of canSee.