SaveInstance

Save supported Object trees with the current XML, binary and decompiler options.

2 functionssUNC 100%Lynx 0.0.0

saveinstance and savegame capture client-resident objects and serialize a place/model file. Snapshot work advances in scheduler slices; decompilation, encoding and disk output continue asynchronously. The caller yields until output has been written and byte-verified. Failures raise an error.

saveinstance

Yields
saveinstance(root: Instance | {Instance}, options: SaveOptions?, filepath: string?): string?

Exports one root or a dense array of roots as one model. Also accepts saveinstance(options?, filepath?), saveinstance(filepath), or saveinstance(root, filepath). With no explicit root, exports game. A DataModel root produces a place; other roots produce a model. Returns the workspace-relative output filename, or no value when CopyToClipboard=true. A positional filepath overrides FilePath in options.

Also available as save_instance and synsaveinstance.

Example

local model = Instance.new("Model")
model.Name = "Example"
local part = Instance.new("Part")
part.Parent = model
local path = saveinstance(model, {Decompile = false, Binary = false}, "example.rbxmx")
print(path)
model:Destroy()

savegame

Yields
savegame(options: SaveOptions?, filepath: string?): string?

Exports game as a place using the same writer and options as saveinstance. Also accepts a filename as its first argument. Returns the output filename, or no value in clipboard mode.

Also available as save_game.

SaveOptions

Option names are case-insensitive. Unknown names are ignored. When synonyms for one field are supplied together, table traversal order decides which assignment wins; use one spelling per field. Mode is recognized by the parser but does not change any setting. These are the implemented options, not options from another saveinstance library.

Binary
Type / defaultboolean = true
Binary .rbxl/.rbxm; false writes XML .rbxlx/.rbxmx. XML is its inverse alias.
CompressionMode
Type / defaultstring | boolean = "zstd"
Binary chunk compression: "zstd", "lz4" or "". true selects zstd; false disables compression. Other strings raise an error.
DisableCompression
Type / defaultboolean = false
true disables compression; false selects zstd.
CompressionLevel
Type / defaultnumber = 9
Converted to an integer, then clamped to -7–22 for Zstandard or 1–12 for LZ4 HC. A chunk is stored uncompressed when compression does not make it smaller.
CopyToClipboard
Type / defaultboolean = false
Alias Clipboard. Forces XML, copies the result instead of writing a file, and returns no value.
Decompile
Type / defaultboolean = true
Alias DecompileScripts. NoScripts is its inverse alias. Enables captured bytecode decompilation for script Source.
KeepUnusedLocals
Type / defaultboolean = true
Explicit decompiler setting; rejects non-booleans.
DecompilerOptions
Type / defaulttable
Decompiler options documented on the Scripts page. Nested fields are applied after top-level KeepUnusedLocals.
DecompileTimeout
Type / defaultnumber = 10
Alias Timeout. Overall decompilation deadline in seconds; finite non-negative values or -1 for no overall deadline.
CpuUsagePercent
Type / defaultnumber = 50
Finite 1–100. Configures snapshot scheduling and decompilation worker budget; not a promise of an exact OS CPU percentage.
DecompileWorkers
Type / defaultinteger = 0
0–32; 0 chooses an automatic worker count.
ScriptTimeout
Type / defaultnumber = 10
Aliases PerScriptTimeout and DecompileScriptTimeout. Per-script limit in seconds, 0.05–300.
ScriptCache
Type / defaultboolean = true
Uses cached decompilation results.
IgnoreDefaultProperties
Type / defaultboolean = true
Alias IgnoreDefaultProps. Omits properties equal to the captured class default.
IgnoreNotArchivable
Type / defaultboolean = true
Alias IgnoreArchivable. true ignores the Archivable restriction and includes such objects.
AvoidFileOverwrite
Type / defaultboolean = true
Adds a numeric suffix for an automatically generated filename that already exists. An explicitly supplied filepath is not protected by this option.
SavePlayerCharacters
Type / defaultboolean = true
Alias SaveCharacters. RemovePlayerCharacters is its inverse alias. Includes player-character models in place capture.
PreservePackageLinks
Type / defaultboolean = false
RemovePackageLinks is its inverse alias. false removes PackageLink metadata from captured output.
PreserveLegacyChat
Type / defaultboolean = false
MigrateLegacyChat is its inverse alias. false performs the writer's legacy-chat cleanup/migration.
PreserveCameraType
Type / defaultboolean = false
Keeps the captured camera type instead of normalizing it for editing. Rejects non-booleans.
RepairCameraFocus
Type / defaultboolean = true
Repairs editor camera focus during output normalization. Rejects non-booleans.
SaveNilInstances
Type / defaultboolean = true
Alias NilInstances. Adds cached detached objects to a NilInstances folder, with detached scripts disabled in the export. Rejects non-booleans.
FilePath
Type / defaultstring
Alias FileName. Workspace-relative output path; a missing extension is chosen from model/place and binary/XML mode.

Output behavior

Without FilePath, a place uses its captured PlaceId as the filename and a model uses saveinstance_model. Missing extensions become .rbxl, .rbxlx, .rbxm or .rbxmx. Place capture excludes CoreGui and CorePackages service roots and does not preserve inaccessible server-only data. The writer loads its current serialization schema asynchronously and validates the bytes written to disk before returning the filename.