Can you save Instances to plugin:SetSetting()?

studio has been down so I can’t test this myself

Does anyone know if you can save Instances to plugin:SetSetting()?

I would assume you can’t since Instances save as rbxm files and plugin settings save in a settings.json file. Does that also mean you can’t save other datatypes like Color3? Is it the same as what could be saved in Datastore?

https://developer.roblox.com/en-us/api-reference/function/Plugin/SetSetting

Just used for storing a key & value. Not an entire place instance.

Okay so can you answer the question? or you don’t know?

can you do plugin:SetSetting("key",Instance.new("Part"))

You cannot. SetSetting does not serialize the data passed to it, so you can only assign primitive types (and tables) to it. You could write a function that serializes and deserializes a part into/from a table, and then use that to save to settings.

local function SerializePart(part)
   -- This is not a full example
  return {
    Name = part.Name;
    Size = {X = part.Size.X, Y = part.Size.Y, Z = part.Size.Z};
    Color = {R = part.Color.R, G = part.Color.G, B = part.Color.B};
  }
end

local function DeserializePart(data)
  local part = Instance.new("Part")
  part.Name = data.Name
  part.Size = Vector3.new(data.Size.X, data.Size.Y, data.Size.Z)
  part.Color = Color3.new(data.Color.R, data.Color.G, data.Color.B)
  return part
end

plugin:SetSetting("MyPart", SerializePart(somePart))
local part = DeserializePart(plugin:GetSetting("MyPart"))
2 Likes