Measure First with Roblox MicroProfiler
Before rewriting a single line of Luau, open the MicroProfiler (Ctrl+F6) on both desktop and a throttled mobile emulator. Look for spikes inside Heartbeat and RenderStepped bars. Most frame drops come from repeated GetDescendants() traversals or unthrottled UI layout recalculations rather than raw arithmetic.
Replace Per-Frame Scans with CollectionService Tags
Scanning Workspace every frame scales linearly with part count. Tag interactive hazards, coins, or tycoon buttons once using CollectionService and react to GetInstanceAddedSignal and GetInstanceRemovedSignal. Combined with --!native on heavy math modules, you can cut script frame time by over 60%.
Avoid Table Churn Inside Tight Loops
Allocating fresh tables inside RenderStepped forces Luau's garbage collector to work overtime. Use table.create(size) when you know the array length upfront, reuse scratch buffers for raycast results, and disconnect unused RBXScriptConnection objects promptly.
Production Luau Reference
--!strict
--!native
table.insert(activeCoins, inst)
end
end