This may sound stupid and unnecessary, however what I'm trying to do is send the descendants of an instance (like workspace) from the client to the server. Using :GetDescendants() I get all the descendants, and that's good, but if I send that to the server, like this:
-- remote function, client side
return workspace:GetDescendants()
And then print the values on the server, like this:
-- remote function, server side
for i, v in pairs(returnedValue) do
print(v.Name)
end
The names printed are only those replicated server-side. I have no way to see the instances that are ONLY on the client-side.
So I had the idea of creating a table with all the instances and their children, and then send that to the server. So I made this:
function EncodeDescendants(ins) --Base instance as arg#1, returns table
local descTable = {
["Name"] = ins.Name,
["ClassName"] = ins.ClassName,
["children"] = {}
}
local childrenToAdd = {}
--
for _, v in pairs(ins:GetChildren()) do
table.insert(childrenToAdd,#childrenToAdd+1,{
["instance"] = v,
["parent"] = descTable
})
end
--
repeat
local newChildrenToAdd = {}
--
for index, v in pairs(childrenToAdd) do
local child = v.instance
local childParent = v.parent
--
local newChildInfo = {
["Name"] = child.Name,
["ClassName"] = child.ClassName,
["children"] = {}
}
--
table.insert(childParent.children,1,newChildInfo)
--
for _, v in pairs(child:GetChildren()) do
table.insert(newChildrenToAdd,1,{
["instance"] = v,
["parent"] = child
})
end
end
--
childrenToAdd = newChildrenToAdd
until #childrenToAdd == 0
--
return descTable
end
But it gives an error: Line 29: invalid argument #1 (table expected, got function) childParent.children should be a table, not a function. Any help is appreciated.
