Logo vun Luau Expert

Luau Expert

Communautéit
afrxo
luau-expert

Modern, strictly-typed Luau. Use whenever writing, reviewing, or fixing Luau code (ModuleScripts, ServerScripts, LocalScripts) — language layer only, not Roblox APIs. Covers strict mode, type system, idioms, asserts, modules, and anti-patterns.

Iwwersiicht

Editeurafrxo
Repositoryroblox-agent-skills
Skill-Nummluau-expert
Stären
21
Forks
4
Matgeliwwert Fichieren
9
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • 9 matgeliwwert Dateien

    Skripten, Virlagen a Referenzen, déi de Modell beim Schaffe liese kann. D'Dateie kënnen nëmme gelies ginn a ginn ni ausgeféiert.

  • Open Source

    Vum afrxo op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Luau Expert an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/afrxo/roblox-agent-skills/tree/main/skills/luau-expert
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/afrxo/roblox-agent-skills.git /tmp/roblox-agent-skills
mkdir -p .claude/skills
cp -r /tmp/roblox-agent-skills/skills/luau-expert .claude/skills/luau-expert
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Luau Expert an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Luau Expert automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Luau Expert net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Luau Language

Write modern, strictly-typed Luau. Source: luau.org.

For deep dives see:

Further reading: references/type-functions-api.md (analysis-time types library), references/type-patterns.md (branded/recursive types, overloads, read-only tables).


Integration Policy

This skill describes preferred patterns; it does not authorize rewriting existing code. Apply rules to new code and code the user explicitly asks to refactor. Match the codebase's existing style (casing, indentation, quote style, module shape) before applying skill defaults. Don't weaken stricter files; don't introduce tooling the project doesn't already use; surface conflicts once and default to the existing pattern.

Full rules: ../../shared/integration-policy.md.


Principles

  • Strictly typed. New files use --!strict. Migrate legacy code; never weaken a file that was strict.
  • Bugs caught at analysis time beat runtime asserts. A typed parameter is worth more than assert(typeof(x) == "number").
  • Simple over clever. Small functions, obvious intent.
  • Prefer immutability. Mutating shared state under yields breaks everything; with React-style libraries it's non-negotiable.
  • Type public APIs fully; skip trivial locals. Annotate anything other modules can call. Don't annotate local n = item.attack(p) — inference handles it.

Mode Header

luau
--!strict      -- default for new files; flags anything that *might* fail at runtime
--!nonstrict   -- legacy migration; infers any when type unknown
--!nocheck     -- generated/third-party only

Project-wide: .luaurc with { "languageMode": "strict" }.


Modern Syntax

luau
-- String interpolation (not string.format / not concat)
print(`Player {name} scored {score} points`)

-- if-then-else expression (not `a and b or c`)
local label = if score >= 100 then "Winner" else "Try again"

-- Generalized iteration (not pairs/ipairs)
for k, v in t do ... end

-- Compound assignments
count += 1
path ..= "/suffix"

-- Continue
for _, item in items do
    if not item.active then continue end
    process(item)
end

-- Floor division
local q = 7 // 2

-- Const bindings (binding immutable; value still mutable)
const MAX_PLAYERS = 16

-- Number separators
local big = 1_000_000

-- Function attributes
@native
local function hotPath(x: number): number
    return x * x + x
end

ipairs only when you specifically need stop-at-first-nil semantics on a sparse array.


Idioms

Early Return / Continue

Guard clauses over pyramids — when the function logically can't keep going, return early.

luau
local function dealDamage(humanoid: Humanoid, damage: number)
    if damage <= 0 then return end
    humanoid.Health -= damage
end

Explicit nil Checks

Most "truthy" checks really mean "not nil". Write what you mean:

luau
if x.Parent ~= nil then ...   -- ✅
if x.Parent then ...          -- ❌ ambiguous

Two exceptions where truthy is fine: if-expressions (if x then a else b reads better than the inverted form) and or defaults.

or for Defaults; Never x and y or z

luau
soundClone.Volume = volume or 0.5

-- Never simulate ternary with and/or — silently wrong when middle value is falsy
local goldAmount = if gamemode == "arena" then nil else 100   -- ✅
-- local goldAmount = gamemode == "arena" and nil or 100      -- ❌ returns 100 even on arena

Don't Hide Builtins

luau
local insert = table.insert    -- ❌
table.insert(items, sword)     -- ✅

No Call-Sugar

luau
call("string")    -- ✅
call({ ... })     -- ✅
call "string"     -- ❌
call { ... }      -- ❌ (StyLua reformats)

Async Suffix on Yielding Functions

luau
local function fetchPlayerDataAsync(userId: number): PlayerData
    -- yields here
end

React (and similar render libraries) does not expect yields — a re-render that hits a yielding call silently corrupts component state. Naming yielding functions makes it visible at the call site.

pcall Method-Shorthand

luau
pcall(part.Destroy, part)                       -- ❌ reads as nonsense
pcall(function() part:Destroy() end)            -- ✅
pcall(saveMoney, player, 100)                   -- ✅ function-shorthand reads naturally

Requires

  • No dynamic requires. require(Modules.X) keeps types; require(child) in a loop erases them.
  • One alphabetical block. No sectioning by package vs local. Use Luau LSP auto-require + StyLua sort_requires (covered in roblox-tooling).

Type System (essentials)

luau
-- Optional
type Maybe<T> = T?              -- T | nil

-- Tagged union (preferred for results)
type Result<T> = { ok: true, value: T } | { ok: false, err: string }

-- Indexed maps where misses are expected
local playerPoints: { [Player]: number? } = {}    -- ✅ checker forces nil-handling
-- { [Player]: number }                            -- ❌ hides bugs on missing keys

-- Optional argument typing — ? at outer position
local function f(default: (boolean | () -> boolean)?) end    -- ✅
-- local function f(default: boolean? | () -> boolean) end   -- ❌

unknown for untrusted input; narrow before use. any for nothing — always reach for unknown first.

Full tour in references/type-system.md.

nil ≠ Nothing

luau
local function returnsNothing() end          -- zero values
local function returnsNil() return nil end   -- one value: nil

print(returnsNothing())   -- (blank)
print(returnsNil())       -- nil

Keep return shape consistent across branches. If a function returns T?, the no-value branch must return nil, not bare return.

String Enums + exhaustiveMatch

The only enum form to use:

luau
type Color = "red" | "green" | "blue"

local function exhaustiveMatch(value: never): never
    error(`Unknown value in exhaustive match: {value}`)
end

local function setColor(color: Color)
    if color == "red" then ...
    elseif color == "green" then ...
    elseif color == "blue" then ...
    else exhaustiveMatch(color)   -- type error if a branch is missed
    end
end

No makeEnum({...}) libraries, no Color = { red = "red" :: Color } wrappers. They give nothing string unions don't.

See examples/exhaustive-match.luau.


Asserts

  • Always pass an error message. Bare assert(cond) produces useless assertion failed!.
  • Constant messages only. assert evaluates its message every call. For formatting use if not cond then error(\...`) end`.
  • Don't assert(typeof(x) == ...) to patch types. If your code is strictly typed, that line never trips except via untyped callers — fix the upstream type instead.
  • At trust boundaries (RemoteEvents, JSON, plugin input) type the input as unknown and narrow:
luau
HurtMe.OnServerEvent:Connect(function(player, damage: unknown)
    if typeof(damage) ~= "number" or damage < 0 then return end
    -- damage: number from here
    dealDamage(player, damage)
end)

Typing the parameter as number makes the runtime check look statically valid even when an exploiter sends a string. unknown forces the check.

See examples/remote-validation.luau.


Modules

luau
--!strict
local OtherModule = require("./OtherModule")

export type Config = { timeout: number, retries: number }

const DEFAULT_CONFIG: Config = { timeout = 30, retries = 3 }

local MyModule = {}

function MyModule.connect(cfg: Config?): ()
    local c = cfg or DEFAULT_CONFIG
    -- ...
end

return table.freeze(MyModule)
  • Always assign and return a named local. No return function() ... end — breaks Ctrl-Shift-F across web/rg.
  • One file per utility. No TableUtil mega-modules; flatten.luau, reverse.luau separately. Luau LSP auto-requires bare names. Project-structure rationale lives in roblox-systems.
  • table.freeze the returned module table to catch accidental mutations.
  • Cyclic deps: cast the imported module to any to break the cycle — and document why.

Shallow Copy, Not Deep

For immutable updates, clone only the path you're touching:

luau
items = table.clone(items)
items[1] = table.clone(items[1])
items[1].durability -= 10

Deep copy is always wasted work under immutability — unrelated subtrees keep their identity, which is exactly what == checks across renders want.

See examples/module-pattern.luau.


OOP — Default to Free Functions

Plain data + free functions over classes. Metatables fight the type checker, hurt grep, and surprise readers.

luau
type Slide = { length: number }
type Video = { slides: { Slide } }

-- videoLength.luau
local function videoLength(video: Video): number
    local total = 0
    for _, slide in video.slides do
        total += slide.length
    end
    return total
end

return videoLength

Aside from __index and __tostring (and __mode for the rare weak table), avoid every metamethod. No __call, no __add, no operator overloads — they don't autocomplete and they fight inference.

When a class is genuinely warranted, see references/typed-class-recipe.md.


Verification Rules

  • Don't assume Lua APIs exist in Luau. Several were removed or relocated:
    • setfenv / getfenv — removed.
    • unpack (global) — moved to table.unpack.
    • loadstring — removed; use loadstring-equivalent only via loadstring if explicitly enabled, otherwise unavailable.
    • bit32 — present, but consider native bitwise operators where possible.
    • goto / labels — not in Luau.
  • Don't invent syntax. If you're unsure whether a feature (e.g. const, @native, type functions, default generics) exists or is stable, check luau.org before using it. State the uncertainty in your reply rather than guessing.
  • Stable concepts beat brittle signatures. If you can express the rule as "use the type system to prevent the bug" rather than "this exact stdlib function takes these exact arguments", do that — Luau's stdlib evolves; the typing principles don't.
  • Roblox APIs are out of scope here. For RemoteEvent, DataStore, Instance, services, etc., defer to the roblox-dev skill. This skill covers the language only.

Anti-Patterns

❌ Don't✅ Do
pairs(t) / ipairs(t)for k, v in t do
string.format(...)`interpolated {value}`
a and b or cif a then b else c
if x.Parent thenif x.Parent ~= nil then
local insert = table.insertInline table.insert
call "x" / call { ... }call("x") / call({ ... })
Reassignable constantsconst MAX = 100
Globalslocal / const
anyunknown + narrowing
Trivial local annotationsLet inference work
Untyped public functionAnnotate params + return
assert(typeof(x) == "T") to patch typesFix the upstream type
assert(cond) no message / formatted messageConstant message; if … then error(…) for formatted
pcall(part.Destroy, part)pcall(function() part:Destroy() end)
{ [K]: V } when keys may be missing{ [K]: V? }
Bare return from a T? functionExplicit return nil
for _, m in c:GetChildren() do require(m)Static require(c.X)
Sectioned require blocksOne alphabetical block
Yielding fn missing Async suffixSuffix Async
makeEnum({"red","green"})type Color = "red" | "green" + exhaustiveMatch
__call / __add / operator metamethodsPlain functions
Anonymous module returnlocal foo = ...; return foo
TableUtil mega-modulesOne function per file
Deep copy for immutable updateClone only the touched path
math.floor(a / b)a // b
Mutating module tabletable.freeze the return
Pyramid nestingEarly returns + continue

Examples

Matgeliwwert Fichieren

De Modell liest dës Dateie bei Bedarf, wärend de Skill gelueden ass. Si ginn als liesbar Dateie bereetgestallt a ginn ni ausgeféiert.

Heefeg gestallte Froen

Wat mécht de KI-Skill Luau Expert?

Modern, strictly-typed Luau. Use whenever writing, reviewing, or fixing Luau code (ModuleScripts, ServerScripts, LocalScripts) — language layer only, not Roblox APIs. Covers strict mode, type system, idioms, asserts, modules, and anti-patterns.

Firwat Luau Expert op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Luau Expert besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Luau Expert an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/afrxo/roblox-agent-skills/tree/main/skills/luau-expert an. TypingMind liest d'Datei SKILL.md, bündelt déi zougehéiereg Dateien an installéiert dat Ganzt als Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Luau Expert benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Luau Expert benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Luau Expert domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Luau Expert gratis?

Jo. De Skill gëtt vum afrxo ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇