As I said, the code was VERY simplified, down to the main problem. I am making a table of custom objects, those custom objects being tables, which contain custom objects that represent a part within the model. Summary: A heavily customized system for a system I am creating myself.
This is not true, I am looking for an alternative OR solution, one that will work.
Here is my full code to satisfy why I need this method:
-- Helperbot3 <3 --
repeat wait() until script:FindFirstChild("structs")
local Structs = script:FindFirstChild("structs")
local CToolsReplicatedStorage = Instance.new("Folder", game.ReplicatedStorage)
CToolsReplicatedStorage.Name = "CToolsReplicatedStorage"
local ServerReady = Instance.new("BoolValue", CToolsReplicatedStorage)
ServerReady.Name = "ServerReady"
local GetModels = Instance.new("RemoteFunction")
GetModels.Name = "GetModels"
local function NewModel(model)
local function NewPartObject(part)
local objb = {
{part.Name},
{part.Anchored},
{Vector3.new(0, 0, 0)},
{part.Rotation},
{part.CanCollide},
{part.Transparency},
{part.Reflectance},
{part.Size}
}
return objb
end
local function NewPart(primary, part)
local obja = {
{part.Name},
{part.Anchored},
{part.Position - primary.Position},
{part.Rotation},
{part.CanCollide},
{part.Transparency},
{part.Reflectance},
{part.Size}
}
return obja
end
local primary = model.PrimaryPart
if(primary ~= nil)then
local primaryPart = NewPartObject(primary)
local modelx = {primaryPart}
for _,i in pairs(model:GetChildren())do
if(i:IsA("BasePart"))then
table.insert(modelx, #modelx+1, NewPart(primary, i))
end
end
else
error("Any additonal models require a primary part to be set. The primary part can be any part within the model.")
end
end
local function getModels()
local models = {}
for _,thing in pairs(Structs:GetChildren()) do
models[#models+1] = NewModel(thing)
end
return models
end
GetModels.OnServerInvoke = nil
local function createModelFromModelObject(obj, startingVector3)
local function createPartFromPartObj(partObj)
local part = Instance.new("Part", workspace)
local pos = startingVector3 + partObj.RelativePosition
local rx, ry, rz = partObj.Rotation.X, partObj.Rotation.Y, partObj.Rotation.Z
part.Name = partObj.Name
part.Anchored = partObj.Anchored
part.CFrame = CFrame.new(pos) * CFrame.Angles(math.rad(rx), math.rad(ry), math.rad(rz))
part.CanCollide = partObj.CanCollide
part.Transparency = partObj.Transparency
part.Reflectance = partObj.Reflectance
part.Size = partObj.Size
return part
end
local model = Instance.new("Model", workspace)
for _,object in pairs(obj) do
local objx = createPartFromPartObj(object)
objx.Parent = model
end
return model
end
local function createViewFromModelObject(obj, startingVector3, transparency)
local objx = obj
for _,part in pairs(objx) do
part.Transparency = transparency
end
return createModelFromModelObject(objx, startingVector3)
end
ServerReady.Value = true
local models = getModels()
print(models)