Skip to content

Example scripts #336

@Nikzed

Description

@Nikzed

Save instances in a place as individual model files example shows us this:

local fs = require("@lune/fs")
local roblox = require("@lune/roblox")

-- Here we load a file just like in the first example
local file = fs.readFile("myPlaceFile.rbxl")
local game = roblox.deserializePlace(file)
local workspace = game:GetService("Workspace")

-- Make sure a directory exists to save our models in
fs.writeDir("models")

-- Then we save all of our instances in Workspace as model files, in our new directory
-- Note that a model file can actually contain several instances at once, so we pass a table here
for _, child in workspace:GetChildren() do
  file = roblox.serializeModel({ child })
  fs.writeFile("models/" .. child.Name, file)
end

I believe it should be fs.writeFile("generated/" .. child.Name .. ".rbxm", file) and contain the .rbxm extension for this files to be usable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions