Lua Formatter — Roblox Scripts Before Code Review

webdev lua-formatter tools

A teammate pastes a LocalScript that arrived as one 400-character line from a decompiler or an old pastebin habit. Review comments become “please indent” instead of “this RemoteEvent can be spoofed.” Lua does not care about indentation. Humans and diff tools do.

Formatting Roblox Lua is about readability and review speed. It is not a compiler pass. Still, bad formatters can annoy Studio if they fight the team’s style or mangle uncommon syntax.

What good formatting changes (and what it must not)

Should change: indentation inside function / then / do / repeat, spacing around operators, consistent newlines before end, table field alignment when it helps.

Must not change: semantics, --[[ comment contents, string literals, require paths, or attribute names that Studio relies on. If a tool rewrites wait() calls or injects globals, stop using it.

-- Before (hostile to review)
local function grab(p)if not p then return end local h=p.Character and p.Character:FindFirstChild("Humanoid")if h then h.Health=0 end end

-- After (still simple Lua)
local function grab(player)
	if not player then
		return
	end

	local character = player.Character
	local humanoid = character and character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

An online Lua formatter is handy for one-off cleanup before a PR when you are not ready to standardize StyLua across the repo. For ongoing work, pick a project formatter and run it in CI.

Roblox-specific review wins

Roblox scripts mix event connections, instance tree walks, and client/server boundaries. Consistent structure makes security notes easier:

  • Group services (Players, ReplicatedStorage) at the top
  • Keep RemoteEvent handlers visually separated from helpers
  • Avoid burying Destroy() calls inside dense one-liners

Indentation will not fix trusting the client — but it will help reviewers see that you did.

Team conventions worth writing down

TopicCommon choiceWhy
IndentTabs (Studio default) or 2 spacesMatch Studio / Rojo
QuotesDouble unless nestedFewer escapes
Table trailing commasAllowedCleaner diffs
Line length~100–120Readable on half screens

Rojo + StyLua (or similar) users should commit the config file so Studio paste and CI output do not thrash. “Format breaks Roblox Studio” usually means mixed tabs/spaces or a plugin fighting another plugin — not that Lua forbids formatting.

Decompiler output hygiene

Decompiled Lua often has:

  • Generic names (v1, v2)
  • goto / labels depending on version
  • Unusual sugar expansions

Format first so control flow is visible, then rename locals in a second pass. Trying to rename inside a single-line soup is how you introduce bugs.

After formatting, run in Studio. Play mode is the real test: formatters rarely break code, but your hand edits during cleanup might.

Diffs reviewers can actually read

Before-and-after formatting should ideally land in its own commit (or PR) so logic changes are not buried in a 2,000-line whitespace storm. When you must mix cleanup and fixes, keep functional edits minimal and call them out in the PR description.

Luau (Roblox’s typed dialect) adds annotations and newer syntax. Confirm your formatter understands the dialect your project uses; a Lua 5.1-oriented tool may mishandle type annotations or certain table shapes. When in doubt, format a single ModuleScript, playtest, then roll the style out repo-wide.

FAQ

Does indent matter to the Lua VM?
No. It matters to diffs, blame, and humans.

Will formatting change performance?
Not in any way you should care about compared to instance thrashing and network.

Should every script be autoformatted?
Yes for team repos. For tiny personal snippets, format when sharing.

Format for humans, then test in Studio. Code review should argue about replication and correctness — not whether end lines up.