/roblox-dev:luau-strict-typingfrom roblox-dev
Provides Luau strict mode typing patterns for Roblox projects: annotations, narrowing Instance? results, forward declarations, typed remotes, generics, and fixing common --!strict type errors.
Ships in roblox-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
All new Luau files should start with --!strict. The type checker catches the
bug classes that dominate Roblox crash logs: nil indexing, wrong remote
payloads, and typo'd properties. These are the patterns that make strict mode
pleasant instead of a fight.
Luau has two type checkers. Since Nov 2025 the new solver is the default
for nonstrict/nocheck scripts, but --!strict scripts stay on the old one
unless the place enables Workspace.UseNewLuauTypeSolver. Error wording and
some features differ, so check which one the project uses before chasing an
error. New-solver features: read-only properties (read x: number), type
functions (keyof<T>, index<T, K>, user-defined type function), and
looser casting rules.
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
type ItemId = string
export type Item = {
id: ItemId,
price: number,
stackable: boolean?,
}
local function priceOf(item: Item, quantity: number): number
return item.price * quantity
end
export type in a ModuleScript lets consumers do
local Types = require(...); local x: Types.Item.Shared/Types.luau module for types that cross the
client/server boundary (remote payloads, profile schema) so both sides agree
by construction.Instance? — the everyday battleFindFirstChild, WaitForChild (in some contexts), and .Character return
optionals. Strict mode forces you to handle nil — good. Idioms:
-- 1. Early-return guard (preferred in handlers)
local root = character:FindFirstChild("HumanoidRootPart")
if not root or not root:IsA("BasePart") then return end
-- root is now BasePart
-- 2. assert when absence is a programmer error, not a runtime possibility
local remotes = ReplicatedStorage:FindFirstChild("Remotes")
assert(remotes, "Remotes folder must exist — created by server bootstrap")
-- 3. :: type assertion ONLY when you have out-of-band certainty
local gui = player:WaitForChild("PlayerGui") :: PlayerGui
Rules of thumb:
:IsA("ClassName") both checks and narrows to that class. Prefer it over
:: Cast because it validates at runtime too.:: assertions sparingly and only through a known-good type;
x :: any :: T is a smell — if you need it, your types are lying somewhere.WaitForChild returns Instance (non-optional overload without timeout),
but with a timeout argument it returns Instance? — handle it.local function a() cannot see local function b() declared later. In strict
mode, declare the variable with its type first, then assign:
--!strict
local openMenu: (menuId: string) -> ()
local closeMenu: () -> ()
closeMenu = function()
-- ... may call openMenu
end
openMenu = function(menuId: string)
-- ... may call closeMenu
end
Assign with name = function(...), not local function name(...) (the latter
creates a new local shadowing your declaration).
Remotes are the untyped hole in every codebase. Close it with a shared types module and validation at the boundary:
-- Shared/Types.luau
export type BuyItemRequest = {
itemId: string,
quantity: number,
}
-- Server: arguments arrive as unknown-shaped values regardless of your types.
-- The annotation documents intent; the VALIDATION enforces it (see the
-- roblox-security skill). Type the handler input as unknown and narrow:
remote.OnServerEvent:Connect(function(player: Player, payload: unknown)
if typeof(payload) ~= "table" then return end
local req = payload :: { [string]: unknown }
if typeof(req.itemId) ~= "string" then return end
if typeof(req.quantity) ~= "number" then return end
handleBuy(player, req.itemId :: string, req.quantity :: number)
end)
Types are compile-time only — they never validate network input. Both layers, always.
--!strict
local Cooldown = {}
Cooldown.__index = Cooldown
export type Cooldown = typeof(setmetatable(
{} :: { duration: number, lastUsed: number },
Cooldown
))
function Cooldown.new(duration: number): Cooldown
return setmetatable({ duration = duration, lastUsed = 0 }, Cooldown)
end
function Cooldown.ready(self: Cooldown): boolean
return os.clock() - self.lastUsed >= self.duration
end
return Cooldown
typeof(setmetatable(...)) derives the instance type including methods.self explicitly in methods defined with dot syntax; or use colon
syntax (function Cooldown:ready()) and let Luau infer self — but the
explicit form gives better errors.local function map<T, U>(list: { T }, fn: (T) -> U): { U }
local out: { U } = table.create(#list)
for i, v in list do
out[i] = fn(v)
end
return out
end
Generic functions cover most needs. Reach for indexers
({ [string]: number }), unions ("sword" | "bow" string literal types) and,
on the new solver, keyof<T> before reaching for any.
Table types are invariant in their value type: a function taking
{ [string]: unknown } rejects a { [string]: Item } catalog. Make it
generic (<V>(map: { [string]: V })) instead of widening the caller.
(Wording below is approximate; it differs between the old and new solver.)
| Error | Fix |
|---|---|
Type 'Instance' does not have key 'Humanoid' | You indexed a generic Instance. Narrow: local h = model:FindFirstChildOfClass("Humanoid"); if not h then return end. |
Type 'Instance?' could be nil | Guard, assert, or restructure so the value is non-optional. Do not sprinkle ::. |
Runtime attempt to call a nil value on a forward-declared function | You used local function name for the assignment, shadowing the declaration, so callers still see the nil original. Use name = function. |
Key 'x' not found in table when building tables incrementally | Declare the full type up front: local t: Item = { id = "", price = 0, stackable = nil } or build with a typed constructor. |
| Recursive type errors on self-referencing tables | Name the type first: type Node = { value: number, next: Node? }. |
never types appearing after narrowing | Two narrowings contradicted (e.g. typeof(x) == "string" inside a branch where x is number). Re-check the logic — the checker found a real bug. |
--!strict to new files only; never big-bang the whole repo.--!nonstrict is the transitional mode; --!nocheck is a last resort for
generated code only.When you (Claude) write any new Luau file, default to --!strict with full
annotations on exported/public functions. Don't ask; it's the standard.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub ivar-anon/roblox-dev --plugin roblox-dev10 skills in this plugin
/new-systemGenerate a complete, secure client/server gameplay system for Roblox — shared types, validated server module, client controller, and remote registration in one pass. Use when adding a feature like a shop, inventory, combat ability, quest, or any system that spans client and server./reviewRun a structured security, data-safety, performance and typing review of Roblox/Luau code using the roblox-reviewer agent. Use when asked to review Roblox code, audit a game for exploits or leaks, or before shipping a system./roblox-architectureRoblox project architecture — ModuleScript patterns over _G, client/server/shared layout, bootstrapping, CollectionService managers, remote organization, and Rojo-friendly structure. Use when starting a Roblox project, adding a new system, restructuring spaghetti scripts, or deciding where code should live.Other plugins' skills for the same job