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

Saved waypoints

Press F6 to drop a waypoint where you stand, and F7 to remove the one closest to you. Each waypoint shows on screen as a diamond with its number and distance. Waypoints are saved per place in your workspace folder, so they are still there the next time you join the same game.

This one brings several parts of the API together: key events, files, JSON and drawings.

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

local FILE = string.format("waypoints/%d.json", game.PlaceId)
local COLOR = Color3.fromRGB(120, 200, 255)

local points = {}  -- each one is { x, y, z }
local marks = {}   -- the drawings for each point

local function loadPoints()
    if isfile(FILE) then
        local ok, data = pcall(function()
            return HttpService:JSONDecode(readfile(FILE))
        end)
        if ok and type(data) == "table" then
            points = data
        end
    end
end

local function savePoints()
    writefile(FILE, HttpService:JSONEncode(points))
end

local function myPosition()
    local character = LocalPlayer.Character
    local root = character and character:FindFirstChild("HumanoidRootPart")
    return root and root.Position
end

local function rebuildMarks()
    for _, mark in ipairs(marks) do
        mark.shape:Remove()
        mark.text:Remove()
    end
    marks = {}
    for _ in ipairs(points) do
        local shape = Drawing.new("Quad")
        shape.Filled = true
        shape.Color = COLOR
        local text = Drawing.new("Text")
        text.FontSize = 13
        text.Center = true
        text.Outline = true
        text.Color = Color3.new(1, 1, 1)
        table.insert(marks, { shape = shape, text = text })
    end
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then
        return
    end
    local here = myPosition()
    if not here then
        return
    end

    if input.KeyCode == Enum.KeyCode.F6 then
        table.insert(points, { here.X, here.Y, here.Z })
        notify("Waypoint " .. #points .. " saved", "Waypoints", 2)
    elseif input.KeyCode == Enum.KeyCode.F7 and #points > 0 then
        local nearest, best = 1, math.huge
        for i, p in ipairs(points) do
            local d = (Vector3.new(p[1], p[2], p[3]) - here).Magnitude
            if d < best then
                nearest, best = i, d
            end
        end
        table.remove(points, nearest)
        notify("Waypoint removed", "Waypoints", 2)
    else
        return
    end
    savePoints()
    rebuildMarks()
end)

RunService.RenderStepped:Connect(function()
    local here = myPosition() or workspace.CurrentCamera.Position
    for i, p in ipairs(points) do
        local mark = marks[i]
        local world = Vector3.new(p[1], p[2], p[3])
        local point, onScreen = WorldToScreen(world)
        if mark and onScreen then
            local s = 7
            mark.shape.PointA = point + Vector2.new(0, -s)
            mark.shape.PointB = point + Vector2.new(s, 0)
            mark.shape.PointC = point + Vector2.new(0, s)
            mark.shape.PointD = point + Vector2.new(-s, 0)
            mark.shape.Visible = true
            mark.text.Text = string.format("#%d  %dm", i, math.floor((world - here).Magnitude))
            mark.text.Position = point + Vector2.new(0, s + 3)
            mark.text.Visible = true
        elseif mark then
            mark.shape.Visible = false
            mark.text.Visible = false
        end
    end
end)

loadPoints()
rebuildMarks()
print(#points, "waypoints loaded for place", game.PlaceId)

Notes

  • Positions are stored as plain { x, y, z } lists because JSON has no Vector3. The script turns them back into vectors when it needs them.
  • InputBegan ignores presses made while Roblox is not the window in front, so typing F6 in another program does nothing.
  • The file name uses the place id, so each game keeps its own list. Look in workspace\waypoints to back them up or share them.