Cant replicate parts from datatable

Im trying to make a part decoder/encoder, and the encoder works fine. Issue is the decoder.


The left set of objects is the encoded model, and the right is the decoded result.

Only issue is that the colors are messed up, and they have studs???

Looking at the encoded JSON file, it gives me the right color values
For example it could say a parts color is 1, 20, 89 and it will just change the values. and its consistent with it too.

Any ideas to fix this?

1 Like

We can’t help you without any code man…

1 Like

Ill send the encoder/decoder code gimmie a sec

1 Like

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
1 Like

Since you’re multiplying by 255 in the encoder, it should be Color3.fromRGB instead of Color3.new.

1 Like

ohhhhh lemem try that
chat limit

1 Like

Yeah that worked, what about the studs thing tho? can i turn hat off while makign a new part?

2 Likes

No idea about the stud’s part, I’d imagine it would be a material problem, check what material it’s setting the decoded parts to

1 Like

ok also, if u didnt realize im not setting the parts rotation. thats becuase for some reason setting its rotation results in it being oddly rotated? could this also be due to me multiplying?

What you could do is InfoTable.CFrame = Part.CFrame:GetComponents()
And it’ll return a table of every single property of the CFrame, to reconstruct it you could simply do

NewCFrame = CFrame.new(table.unpack(PartInfoTable.CFrame))

Which has no problems with rotation.

its just giving me 1 number
image

Another thing I would recommend would be to setup your own API dump and use that to reconstruct a property table of the part you’re trying to encode to get every property.
Here’s what I’m using, if you want you could make an HTTP request to the json file or setup your own CloudFlare Worker.

Oh right, sorry my knowledge of this is previous code made by another person.
You also have to do

{Part.CFrame:GetComponents()}

that works! thanks for all the help, ill figure out the whole studs thing later.

1 Like

are you still here? i do have ONE more issue
The decoder sometimes gives me massive strings, and i cant find out how to go about copying them. Printing doesntwork because it just cuts it off and says “trimmed”, and i cant make it the text of a text label, because it syas its too long. What can i do?

If you want to copy the string, just put it in a table like

print({"Really long string"}

and it should print the entire string, once you expand the table.

no wonder it trimmed it, the string is 700kb, thats pretty big man

i cant decode it, i think the filesize is too big

Your string should not be 700kb in general, it means your encoder is doing something very wrong and is creating a ton of junk data. more than likely anyway, unless your encoding a bunch of parts.

i am decoding a lot of parts, like a lot a lot of parts.