I’m messing around with datastore and trying to make a script that converts a folder of values into a dictionary of dictionaries.
Have you figured out any smart ways to do that? Doing this the other way around would be easy, but creating dictionaries isn’t my piece of cake. I tried going through them all manually with for loops but it feels kind of… Clunky, and limits the amount of children to be added.
And how would I store the value of the dogs hair for an example as its already assigned to start a new dictionary? Add it as first object in the dictionary or include it in the key as:
I wasn’t sure on the value types/how many layers of instances you intend to have but here.
local folder = workspace:WaitForChild("Folder") --change workspace
local save = {}
for _, pet in ipairs(workspace:GetChildren()) do
if pet.Value then --check for pet
save[pet.Name] = {} --create new array for pet
for i, feature in ipairs(pet:GetChildren()) do
if feature.Value then --check for feature
save[pet.Name][feature.Name] = {} --create new array for feature
for _, trait in ipairs(feature:GetChildren()) do
if trait.Value then --check for trait
save[pet.Name][feature.Name][trait.Name] = trait.Value --assign trait value to trait item in array
end
end
end
end
end
end
local folder = --Path to ur folder
local dictaOfValues = {}
for _, v in pairs(folder:GetChildren()) do
if v:IsA("ValueBase") then do
folder[v.Name] = {}
end
for _, w in pairs(v:GetChildren()) do
if v:IsA("ValueBase") then do
folder[v.Name] = w
end
end
end
Tried pretty much what you did here before I posted this, but I need it to create a deeper list of dictionaries.This only goes down by two steps, I’d need something to iterate through the whole folder 'till the deepest end.