· 5 years ago · Nov 05, 2020, 05:32 PM
1local function DictionaryComponents(Dictionary: Dictionary, Parent: string, Descendants: Dictionary?) --> Nil
2 for index, value in pairs(Dictionary) do
3 local valueType = typeof(value)
4
5 if valueType == "table" then
6 local valueParent = Descendants and Descendants[index]
7
8 -- If the object does not have a parent then lets create a subfolder (because tables are folders)
9 if not valueParent then
10 local folder = Make("Folder", {Name = index, Parent = Parent})
11 DictionaryComponents(value, folder) -- Folder is going to be the parent
12
13 continue
14 end
15
16 -- If the object exists then
17 local createable_instances = {}
18
19 for objName, objValue in pairs(value) do
20 -- if the object already exists
21
22 local Object = valueParent:FindFirstChild(objName)
23
24 if Object then
25 local objChildren = Object:GetChildren()
26
27 for _, subObject in pairs(objChildren) do
28 if not Object:FindFirstChild(subObject.Name) then
29 continue
30 end
31
32 if subObject:IsA("Folder") then
33 continue
34 end
35
36 subObject.Value = objValue[subObject.Name]
37 end
38
39 continue
40 end
41
42 createable_instances[objName] = objValue
43 end
44
45 DictionaryComponents(createable_instances, valueParent)
46
47 continue
48 end
49
50 -- If the typeof value is not "table" then lets create a value
51 local Object = Parent:FindFirstChild(index)
52
53 if Object then
54 Object.Value = value
55
56 continue
57 end
58
59 local List = {Name = index, Value = value, Parent = Parent}
60 Make(PossibleTypes[valueType], List)
61 end
62end