Having trouble turning a table into a modulescript in my plugin

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to make a plugin that turns parts into modulescript

  1. What is the issue? Include screenshots / videos if possible!

It works, but the size, position, and color are all set to “Null”

local toolbar = plugin:CreateToolbar("Part to Module script")

local newscriptbutton = toolbar:CreateButton("Convert Parts to Modules", "Convert Parts to Modules", "rbxassetid://1")

local Selection = game:GetService("Selection")

local Data = {}



newscriptbutton.Click:Connect(function()
	local newmodule = Instance.new("ModuleScript")
	for i,v in pairs(Selection:Get()) do
		if v:IsA("Model") then
			for x,part in pairs(v:GetDescendants()) do
				if part:IsA("Part") then
					local rand = math.random(1,100000)
					Data[part.Name.. tostring(rand)] = {}
					Data[part.Name.. tostring(rand)]["CFrame"] = part.CFrame
					Data[part.Name.. tostring(rand)]["Color"] = part.Color
					Data[part.Name.. tostring(rand)]["Size"] = part.Size
					Data[part.Name.. tostring(rand)]["PositionOffset"] = workspace.OriginPart.Position - part.Position
				end
			end
		else
			if v:IsA("Part") then
				local part = v
				local rand = math.random(1,100000)
				Data[part.Name.. tostring(rand)] = {}
				Data[part.Name.. tostring(rand)]["CFrame"] = part.CFrame
				Data[part.Name.. tostring(rand)]["Color"] = part.Color3
				Data[part.Name.. tostring(rand)]["Size"] = part.Size
				Data[part.Name.. tostring(rand)]["PositionOffset"] = workspace.OriginPart.Position - part.Position
			end
		end
	end
	newmodule.Parent = game.Workspace
	
	newmodule.Source = "local module = ".. tostring(game:GetService('HttpService'):JSONEncode(Data)).. ' return module'
end)

Because you’re encoding the data to JSON, and JSON tables aren’t the same as Lua tables, you’d need to make your own table encoder :stuck_out_tongue:

i have no idea how to make a table encoder

Also JSON doesnt support CFrames, Color3s, or Vector3s. Numbers, strings, or booleans only

the rbxm file containing the script is deleted, sorry