Model importer only reads one property of a JSON when it is input in the "Create" function

I am scripting a model exporter plugin for a Roblox game called “RetroStudio”, however there is one thing that I couldn’t seem to find out. Whenever the JSONs get inputted into the Roblox Studio plugin interface, the “Create” function in the importer module does not seem to return a list of properties and instead only returns one property and its value.

The importer module is scripted as follows:

local httpService = game:GetService("HttpService")
local constructors = require(script.Constructors)

local plugin = script.Parent

local cleaned = 0
local baseParent = nil

local definedParents = {}

local function construct(n, v, obj)
	local func = constructors[typeof(obj[n])]

	if func then 
		return func(v)
	else
		return v
	end
end

local function refine(jsons)
	-- Refines every JSON submitted to the importer UI, returning a proper Lua table
	-- that the model importer can fully use without doing multiple
	-- operations in the background.

	local function refineError(reason)
		return {false, reason, {}}
	end

	if jsons == nil then return unpack(refineError("No JSONs were input.")) end

	local success, error = pcall(function()
		jsons = httpService:JSONDecode(jsons)

		local first = jsons[1]

		-- Create the first object.
		local obj = Instance.new(first.ClassName)
		first.ClassName = nil

		for n, v in pairs(first) do
			local value = construct(n, v, obj)
			obj[n] = value
		end

		baseParent = obj
		table.remove(jsons, 1)
		table.insert(definedParents, first.Parent)

		for i, json in pairs(jsons) do
			if table.find(definedParents, json.Parent) then
				-- Parent exists; add the object to the defined parents list.
				table.insert(definedParents, `{json.Parent}.{json.Name}`)
			else
				-- Parent does not exist; move it to the index after the definition.
				local paths = json.Parent:split(".")
				local descendant = paths[#paths]

				for j=i, #jsons do
					if jsons[j].Name == descendant then
						jsons[i] = jsons[j + 1]
						break
					end
				end
			end
		end
	end)

	return success, error, jsons
end

local function create(lua)
	local startTime = os.clock()

	local success, fail = pcall(function()
		for _, props in pairs(lua) do
			local obj = Instance.new(props.ClassName)
			obj.Name = props.Name
			props.Name = nil
			props.ClassName = nil

			for n, v in pairs(props) do
				if n == "Name" and baseParent:FindFirstChild(v, true) then 
					cleaned += 1
					obj:Destroy()
					continue
				end

				local value = construct(n, v, obj)
				obj[n] = value
			end
		end
	end)

	if not success then
		warn("Error found! Error:", fail)
	end

	local endTime = os.clock()
	print("Created object(s) in:", endTime - startTime)
end

return function(jsons)
	local startTime = os.clock()
	local iters = 0

	local success, reason, refined = refine(jsons[1])

	if success then
		for _, json in pairs(refined) do
			iters += 1
			
			warn("--- JSON #"..iters.." ---")		

			create(json)
		end

		local endTime = os.clock()
		warn("Imported in:", endTime - startTime)

		if cleaned > 0 then
			warn("Amount of duplicates removed:", cleaned)
		else
			warn("No duplicates found. Your model is healthy from that weird bug!")
		end

		cleaned = 0
		baseParent = nil
		definedParents = {}
	else
		warn("JSONs were malformed or there was an error refining the JSONs. Please try again. Error:", reason)
	end
end

Example: [multiple JSONs of object properties] each JSON gets put into the “Create” function as a [JSON containing object properties] but suddenly it turns into [one object property]

Here is a media-based example. As you can see it returns mainly “Reflectance” and “0” instead of a table of properties.
image

Still have not figured it out yet…

What do you mean the create function? The function named create nor the function return by the module explicitly return.

I meant to say that I think the create function caused the issue. I think this because when each JSON gets input into the create function, it only reads one property and value.

I’m not sure what you think what function or lines of code caused the issue, but simply state them on another reply and I’ll check them out. Sorry if I misread your reply.

Oh okay. I was confused by what you meant by return when you said “the importer module does not seem to return a list of properties and instead only returns one property and its value”.

If the pcall is running into an error that would explain why it stops after one property and value pair. If you think the error is happening in the create function I would recommend printing out lua to make sure it’s in the format you’re expecting. You could also use an online JSON viewer to verify the JSON is in the format you’re expecting too.

It seems like the problem is probably that the data your functions are getting aren’t in the format you expect.