Syntax
local values = table.create(count, initialValue)Examples
Luau preallocated arrays
Run as a standalone current Luau script, or as a Script in Roblox Studio ServerScriptService. No Roblox engine APIs are required; type-annotated syntax is not standard Lua.
local reserved = table.create(3)
local filled = table.create(3, 0)
print(#reserved, #filled)
for i = 1, 3 do reserved[i] = i * i end
print(table.concat(reserved, ","))- Output: 0 and 3, then 1,4,9. Reserved capacity is not the same as existing elements.
Best practices
- Use this for known array capacities, not dictionaries. A table used as the fill value is the same shared table in every slot.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation