Script Not Adding Code To Script

I’m trying to make a map to script plugin and I added a pcall to the script it generates but it doesn’t add the end)?

local button = plugin:CreateToolbar("Model To Script"):CreateButton("Convert", "", "")
local selection = game:GetService("Selection")

local index = function(object, key)
    return object[key]
end

button.Click:Connect(function()
	for i,v in pairs(selection:Get()) do
		if v:IsA("Model") then
			local scripta = Instance.new("Script", workspace)
			scripta.Source = scripta.Source.."pcall(function()"
			for a, b in pairs(v:GetDescendants()) do
				if b:IsA("Script") then
				else
					scripta.Source = scripta.Source.." o"..a.." = Instance.new('"..b.ClassName.."', workspace)"
					for e, t in pairs(GetProperties(b)) do
						pcall(function()
							if t == "ClassName" or t == "Source" or t == "RobloxLocked" then
							else
								if t == "CFrame" then
									scripta.Source = scripta.Source.." o"..a.."."..t.." = ".."CFrame.new("..tostring(index(b, t))..")"
								elseif t == "BrickColor" then
									scripta.Source = scripta.Source.." o"..a.."."..t.." = ".."BrickColor.new('"..tostring(index(b, t)).."')"
								elseif t == "Position" or t == "RotVelocity" or t == "Size" or t == "Velocity" then
									scripta.Source = scripta.Source.." o"..a.."."..t.." = ".."Vector3.new("..tostring(index(b, t))..")"
								elseif t == "Color" then
									scripta.Source = scripta.Source.." o"..a.."."..t.." = ".."Color3.new("..tostring(index(b, t))..")"
								--elseif t == "Material" then
									--scripta.Source = scripta.Source.."\no"..a.."."..t.." = "..tostring(index(b, t))
								elseif string.match(tostring(index(b, t)), "Enum") or t == "PrimaryPart" then
									scripta.Source = scripta.Source.." o"..a.."."..t.." = "..tostring(index(b, t))
								elseif t == "C0" or t == "C1" then
									scripta.Source = scripta.Source.." o"..a.."."..t.." = ".."CFrame.new("..tostring(index(b, t))..")"
								elseif t == "Parent" or t == "Part0" or t == "Part1" then
									scripta.Source = scripta.Source.." o"..a.."."..t.." = ".."workspace"
								--elseif string.match(tostring(index(b, t)), 1) or string.match(tostring(index(b, t)), 2) or string.match(tostring(index(b, t)), 3) or string.match(tostring(index(b, t)), 3) or string.match(tostring(index(b, t)), 4) or string.match(tostring(index(b, t)), 5) or string.match(tostring(index(b, t)), 6) or string.match(tostring(index(b, t)), 7) or string.match(tostring(index(b, t)), 8) or string.match(tostring(index(b, t)), 9) or string.match(tostring(index(b, t)), 0) then
									--scripta.Source = scripta.Source.."\no"..a.."."..t.." = "..tonumber(index(b, t))
								else
									scripta.Source = scripta.Source.." o"..a.."."..t.." = ".."[["..tostring(index(b, t)).."]]"
								end
							end
						end)
					end
				end
			end
			scripta.Source = scripta.Source.." end)"
		end
	end
end)
1 Like

Can you put a print in after the scripta line where " end)" is added to see if you actually get to that part of the code.