Syntax
local bytes = buffer.create(4); buffer.writeu16(bytes, 0, value)Examples
Luau binary buffers
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 bytes = buffer.create(4)
buffer.writeu16(bytes, 0, 513)
buffer.writeu16(bytes, 2, 7)
print(buffer.len(bytes))
print(buffer.readu8(bytes, 0), buffer.readu8(bytes, 1))
print(buffer.readu16(bytes, 2))- Output: 4; then 1 and 2; then 7. The 16-bit value 513 is stored as bytes 1,2 at offsets 0 and 1.
Best practices
- Check bounds and value ranges before writes. Offsets are zero-based even though ordinary Luau sequences are one-based.
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