Encoder:
local Proto = {
}
Proto.DecodePart = function(Part)
warn("Decoding part: "..Part.Name)
local InfoTable = {}
local Tags = {}
--JSON does notsupport some things, so they are converted to strings/tables.
--Appearance:
InfoTable.BrickColor = tostring(Part.BrickColor)
InfoTable.CastShadow = Part.CastShadow
InfoTable.Color = {math.round(Part.Color.R*255), math.round(Part.Color.G*255), math.round(Part.Color.B*255)} --Rounded because floating points
InfoTable.Material = tostring(Part.Material)
InfoTable.Reflectance = Part.Reflectance
InfoTable.Transparency = Part.Transparency
--Data:
InfoTable.Archivable = Part.Archivable
InfoTable.Locked = Part.Locked
InfoTable.Name = Part.Name
--No Parent Required
--Transform
InfoTable.Size = {Part.Size.X, Part.Size.Y, Part.Size.Z}
InfoTable.CFramePos = {Part.CFrame.Position.X, Part.CFrame.Position.Y, Part.CFrame.Position.Z}
InfoTable.CFrameRot = {Part.Rotation.X, Part.Rotation.Y, Part.Rotation.Z}
--Behavior
InfoTable.EnableFluidForces = Part.EnableFluidForces
--Collision
InfoTable.CanCollide = Part.CanCollide
InfoTable.CanQuery = Part.CanQuery
InfoTable.CanTouch = Part.CanTouch
InfoTable.CollisionGroup = Part.CollisionGroup
--Part
InfoTable.Anchored = Part.Anchored
InfoTable.CustomPhysicalProperties = Part.CustomPhysicalProperties
InfoTable.Massless = Part.Massless
InfoTable.RootPriority = Part.RootPriority
InfoTable.Shape = tostring(Part.Shape)
--Tags
for _, V in Part:GetTags() do
table.insert(Tags, V)
end
local FinalTable = {}
table.insert(FinalTable, InfoTable)
table.insert(FinalTable, Tags)
warn("Finished Decoding: "..Part.Name)
return FinalTable
end
return Proto
Decoder:
local function DecodePart(PartInfoTable)
local NewObject = Instance.new("Part")
NewObject.Anchored = true
local PartInfoTableCFrame = CFrame.new(Vector3.new(PartInfoTable.CFramePos[1], PartInfoTable.CFramePos[2], PartInfoTable.CFramePos[3]))
print(PartInfoTableCFrame)
print(Color3.new(PartInfoTable.Color[1], PartInfoTable.Color[2], PartInfoTable.Color[3]))
--Appearance
NewObject.BrickColor = BrickColor.new(PartInfoTable.BrickColor)
NewObject.CastShadow = PartInfoTable.CastShadow
NewObject.Color = Color3.new(PartInfoTable.Color[1], PartInfoTable.Color[2], PartInfoTable.Color[3])
NewObject.Material = Enum.Material[string.split(PartInfoTable.Material, "Enum.Material.")[2]]
NewObject.Reflectance = PartInfoTable.Reflectance
NewObject.Transparency = PartInfoTable.Transparency
--Data:
NewObject.Archivable = PartInfoTable.Archivable
NewObject.Locked = PartInfoTable.Locked
NewObject.Name = PartInfoTable.Name
--No Parent Required
--Transform
NewObject.Size = Vector3.new(PartInfoTable.Size[1], PartInfoTable.Size[2], PartInfoTable.Size[3])
NewObject.CFrame = PartInfoTableCFrame
--Behavior
NewObject.EnableFluidForces = PartInfoTable.EnableFluidForces
--Collision
NewObject.CanCollide = PartInfoTable.CanCollide
NewObject.CanQuery = PartInfoTable.CanQuery
NewObject.CanTouch = PartInfoTable.CanTouch
NewObject.CollisionGroup = PartInfoTable.CollisionGroup
--Part
NewObject.Anchored = PartInfoTable.Anchored
NewObject.CustomPhysicalProperties = PartInfoTable.CustomPhysicalProperties
NewObject.Massless = PartInfoTable.Massless
NewObject.RootPriority = PartInfoTable.RootPriority
NewObject.Shape = Enum.PartType[string.split(PartInfoTable.Shape, "Enum.PartType.")[2]]
NewObject.Parent = game.Workspace
return NewObject
end
local String = [=[ [[{"Reflectance":0,"Color":[248,248,248],"Anchored":false,"CFramePos":[22.000015258789064,1.4955581426620484,-21.99994659423828],"Locked":false,"Material":"Enum.Material.Plastic","Archivable":true,"Size":[4,3,4],"Shape":"Enum.PartType.Block","CanCollide":true,"CollisionGroup":"Default","RootPriority":0,"EnableFluidForces":true,"Massless":false,"Transparency":0,"BrickColor":"Institutional white","CanTouch":true,"CanQuery":true,"CFrameRot":[0.003000000026077032,0.0010000000474974514,0],"CastShadow":true,"Name":"Part"},[]],[{"Reflectance":0,"Color":[13,105,172],"Anchored":false,"CFramePos":[17.999879837036134,0.4929446578025818,-22.000120162963868],"Locked":false,"Material":"Enum.Material.Plastic","Archivable":true,"Size":[4,1,4],"Shape":"Enum.PartType.Block","CanCollide":true,"CollisionGroup":"Default","RootPriority":0,"EnableFluidForces":true,"Massless":false,"Transparency":0,"BrickColor":"Bright blue","CanTouch":true,"CanQuery":true,"CFrameRot":[-0.00800000037997961,0.003000000026077032,-0.003000000026077032],"CastShadow":true,"Name":"Part"},[]],[{"Reflectance":0,"Color":[17,17,17],"Anchored":false,"CFramePos":[14.000064849853516,1.495539903640747,-22.00002098083496],"Locked":false,"Material":"Enum.Material.Plastic","Archivable":true,"Size":[4,3,4],"Shape":"Enum.PartType.Block","CanCollide":true,"CollisionGroup":"Default","RootPriority":0,"EnableFluidForces":true,"Massless":false,"Transparency":0,"BrickColor":"Really black","CanTouch":true,"CanQuery":true,"CFrameRot":[0.003000000026077032,-0.0010000000474974514,0],"CastShadow":true,"Name":"Part"},[]],[{"Reflectance":0,"Color":[117,0,0],"Anchored":false,"CFramePos":[17.999977111816408,2.4853668212890627,-22.00001335144043],"Locked":false,"Material":"Enum.Material.Plastic","Archivable":true,"Size":[4,1,4],"Shape":"Enum.PartType.Block","CanCollide":true,"CollisionGroup":"Default","RootPriority":0,"EnableFluidForces":true,"Massless":false,"Transparency":0,"BrickColor":"Maroon","CanTouch":true,"CanQuery":true,"CFrameRot":[-0.003000000026077032,0.0010000000474974514,-0.006000000052154064],"CastShadow":true,"Name":"Part"},[]],[{"Reflectance":0,"Color":[91,154,76],"Anchored":false,"CFramePos":[18.00007438659668,1.4880410432815552,-21.999942779541017],"Locked":false,"Material":"Enum.Material.Plastic","Archivable":true,"Size":[4,1,4],"Shape":"Enum.PartType.Block","CanCollide":true,"CollisionGroup":"Default","RootPriority":0,"EnableFluidForces":true,"Massless":false,"Transparency":0,"BrickColor":"Shamrock","CanTouch":true,"CanQuery":true,"CFrameRot":[0.008999999612569809,-0.0010000000474974514,0.0010000000474974514],"CastShadow":true,"Name":"Part"},[]]] ]=]
local Table = game.HttpService:JSONDecode(String)
print(Table)
for _, V in Table do
DecodePart(V[1])
end