$npx -y skills add TabooHarmony/roblox-brain --skill roblox-luau-patternsUse for Luau metatable classes, inheritance, Promises, coroutines, pcall, module structure, services, and Roblox coding patterns.
| 1 | ## When to Load |
| 2 | |
| 3 | Load for Luau patterns: classes with metatables (constructors, methods, inheritance), async control flow (Promises, coroutines, pcall/xpcall), module structure (service pattern, singletons), Roblox-specific patterns (Instance creation, service access, events, task library). For syntax questions, use `roblox-luau-core`. For type annotations, use `roblox-luau-types`. |
| 4 | |
| 5 | **Hand off when:** Pure syntax → `roblox-luau-core` · Type annotations → `roblox-luau-types` · Networking/data/security → `roblox-networking`, `roblox-data`, `roblox-security` · Performance → `roblox-performance`. |
| 6 | |
| 7 | Full examples and code samples: `references/full.md` |
| 8 | |
| 9 | ## Quick Reference |
| 10 | |
| 11 | **OOP (metatables):** Use for multiple instances with shared behavior. |
| 12 | ```luau |
| 13 | local MyClass = {} |
| 14 | MyClass.__index = MyClass |
| 15 | function MyClass.new(...): MyClass -- . for constructors |
| 16 | return setmetatable({...}, MyClass) |
| 17 | end |
| 18 | function MyClass:method() -- : for methods (implicit self) |
| 19 | end |
| 20 | -- Inheritance: setmetatable(Child, { __index = Parent }) |
| 21 | ``` |
| 22 | Always set `__index`. Constructors use `.`, methods use `:`. |
| 23 | |
| 24 | **Module Services:** Singleton pattern for managers. `Service.init()` wires events; clean up in `PlayerRemoving`. |
| 25 | |
| 26 | **Instance Creation:** Configure ALL properties, set `Parent` LAST (prevents replication races). |
| 27 | |
| 28 | **Task Library:** Always use `task.*`. `wait()`/`spawn()`/`delay()` are deprecated. |
| 29 | |
| 30 | **Error Handling:** |
| 31 | ```luau |
| 32 | local ok, result = pcall(fn, args...) -- one-shot fallible calls |
| 33 | local ok, result = xpcall(fn, handler) -- custom error handler + traceback |
| 34 | ``` |
| 35 | Wrap ALL DataStore/HTTP calls. Use a Promise library for async chains when the project already has one; otherwise use `task` and explicit error handling. |
| 36 | |
| 37 | **Naming:** PascalCase (classes/modules/types), camelCase (vars/functions), UPPER_CASE (constants). Prefix `_` for private. |
| 38 | |
| 39 | **Anti-Patterns:** |
| 40 | - `wait()`/`spawn()`/`delay()` → `task.*` |
| 41 | - Polling loops → events or Heartbeat |
| 42 | - String `..` in loops → `table.concat()` |
| 43 | - Missing `pcall` on DataStore/HTTP → silent crash |
| 44 | - Trusting client → validate types, ranges, ownership |
| 45 | - Parent before config → replication race |
| 46 | - Props on class table instead of `self` → shared across instances |
| 47 | - No connection cleanup → use Trove or manual `:Disconnect()` |
| 48 | |
| 49 | **Libraries:** Promise · Trove · Signal · Comm · Component · Concur · TypedRemote (Sleitnick) · ProfileStore · t (runtime checks) |
| 50 | |
| 51 | **Checklist:** `__index` set · `.`/`:` correct · pcall on fallible · cleanup · Parent last · no deprecated · clear API · player data cleaned on leave |