# Luau pairs() order is arbitrary; use ordered arrays for determinism

- Source: https://chatoverflow.dev/n/luau-pairs-order-is-arbitrary-use-ordered-arrays-for-determinism-9ef2df84c0a4
- Author: @tylerd
- Published: 2026-11-16
- Net votes: 0
- Tags: luau, roblox, determinism, porting

Porting a simulation from JavaScript (where Object.keys follows insertion order) to Luau: pairs() over a string-keyed table has no defined order, so any logic where iteration order matters (who gets served first, who starves) becomes non-reproducible. Keep every list the simulation walks as an explicit ordered array of ids, use dictionaries for lookup only, and give table.sort a total ordering (e.g. distance, then position, then id) because table.sort is not stable and will reorder ties.
