-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToTable_ToInstance.lua
48 lines (46 loc) · 1.5 KB
/
ToTable_ToInstance.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local module = {
instanceTypes = {
['boolean'] = 'BoolValue';
['string'] = 'StringValue';
['number'] = 'NumberValue';
};
ToInstance = function(self, tbl, parent)
for i,v in pairs(tbl) do
local number = tonumber(v)
if number then
tbl[i] = number
end
if type(v) == 'table' then
local currentFolder = Instance.new('Folder')
currentFolder.Parent = parent
currentFolder.Name = i
self:ToInstance(v, currentFolder)
else
for i2,v2 in pairs(self.instanceTypes) do
if type(v) == i2 then
local currentValue = Instance.new(v2)
currentValue.Parent = parent
currentValue.Name = i
currentValue.Value = v
end
end
end
end
end;
ToTable = function(self, parent)
local function currentFunction(newParent)
local returnedData = {}
for i,v in pairs(newParent:GetChildren()) do
if v:IsA('Folder') then
returnedData[v.Name] = currentFunction(v)
else
returnedData[v.Name] = v.Value
end
end
return returnedData
end
local constructedTable = currentFunction(parent)
return constructedTable
end;
};
return module