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

Name tags with a settings tab

Text over each player's head with their name, health and distance, and a menu tab to set it up. The tab has an on/off toggle with a keybind, a team check, a colour, a text size and a distance limit. The values are saved with the script, so they come back the next time you run it.

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

local bind

UI.AddTab("Name tags", function(tab)
    local main = tab:Section("Name tags", "Left")
    main:Toggle("tags_on", "Enabled", true)
    bind = main:Keybind("tags_key")
    bind:ShowInKeybinds("Name tags", "tags_on")
    main:Toggle("tags_team", "Hide teammates", true)
    main:Toggle("tags_health", "Show health", true)
    main:Toggle("tags_distance", "Show distance", true)

    local look = tab:Section("Look", "Right")
    look:Toggle("tags_color_on", "Custom colour")
    look:ColorPicker("tags_color", 1, 1, 1, 1)
    look:SliderInt("tags_size", "Text size", 10, 24, 14)
    look:SliderInt("tags_range", "Max distance", 50, 3000, 1000)
    look:Tip("In studs")
end)

local tags = {}

local function tagFor(player)
    local tag = tags[player]
    if not tag then
        tag = Drawing.new("Text")
        tag.Center = true
        tag.Outline = true
        tags[player] = tag
    end
    return tag
end

local function lineFor(player, humanoid, distance)
    local parts = { player.DisplayName }
    if UI.GetValue("tags_health") then
        parts[#parts + 1] = string.format("%d hp", math.floor(humanoid.Health))
    end
    if UI.GetValue("tags_distance") then
        parts[#parts + 1] = string.format("%dm", math.floor(distance))
    end
    return table.concat(parts, "  ")
end

RunService.RenderStepped:Connect(function()
    local enabled = UI.GetValue("tags_on") and bind ~= nil and bind.value
    local camera = workspace.CurrentCamera
    local range = UI.GetValue("tags_range")
    local size = UI.GetValue("tags_size")
    local color, alpha = Color3.new(1, 1, 1), 1
    if UI.GetValue("tags_color_on") then
        color, alpha = UI.GetValue("tags_color")
    end

    local present = {}
    for _, player in ipairs(Players:GetPlayers()) do
        if player ~= LocalPlayer then
            present[player] = true
            local tag = tagFor(player)
            local character = player.Character
            local head = character and character:FindFirstChild("Head")
            local humanoid = character and character:FindFirstChildOfClass("Humanoid")
            local teammate = player.Team ~= nil and player.Team == LocalPlayer.Team
            local shown = false

            if enabled and head and humanoid and humanoid.Health > 0
                and not (teammate and UI.GetValue("tags_team")) then
                local distance = (head.Position - camera.Position).Magnitude
                local point, onScreen = WorldToScreen(head.Position + Vector3.new(0, 1.5, 0))
                if onScreen and distance <= range then
                    tag.Text = lineFor(player, humanoid, distance)
                    tag.Position = point - Vector2.new(0, size)
                    tag.FontSize = size
                    tag.Color = color
                    tag.Transparency = alpha
                    shown = true
                end
            end
            tag.Visible = shown
        end
    end

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

How it fits together

  • The tab function only declares widgets. The drawing happens in RenderStepped, which reads the current values with UI.GetValue each frame.
  • bind has no default key, so it starts in "always" mode and the tags show as soon as the toggle is on. Bind a key in the menu to make it a hold or toggle key.
  • The keybind is listed in evasive's keybind list (Misc > Panels > Keybind list) while "Enabled" is on.