How to convert all properties of an instance into a dictionary?

How could I get all properties of a part and transform this into a dictionary?
For example:

… this should be something like:

MyTable = {
["Part"] = 
    {Name = "Part", 
     BrickColor = "Medium stone grey", 
     CastShadow = true, 
     Color = Vector3.new...}
}

According to this, you can’t get a list of the properties as keys.
I remember there being a module (idk the name) that did this for you though. I believe it pretty much has an array of property names for each Class though, so you’d need to manually fill that in.

if you’re trying to make it yourself, it would look something like this:

-- I picked Decal and ClickDetector because they don't have too many properties
-- This is a dictionary that stores all the property names of each class
Classes = {
   ["Decal"] = { Color3, LocalTransparencyModifier, Texture, Transparency, ZIndex, Face, Archivable, ClassName, Name, Parent },
   ["ClickDetector"] = { CursorIcon, MaxActivationDistance, Archivable, ClassName, Name, Parent },
   ...
}

function toDictionary(someInstance)
   local data = {}
   -- for each property name in the instance's class, get the value from the instance and store in dictionary
   for _, propertyName in ipairs(Classes[someInstance.ClassName]) do
      data[propertyName] = someInstance[propertyName]
   end

   return data
end

someDecal = ...
data = toDictionary(someDecal)
2 Likes

This is where you would use an API Dump, which holds a description of all classes and their members.

Here are some useful resources:

2 Likes