-- its best to anchor while welding, and then unanchor when finished


parts_table=script.Parent:GetChildren()

round=function(num)
local a,b=math.modf(num)
if num%1~=0 then 
	return math.floor(num)+math.floor(b*10)/10
else
	return math.floor(num)
end end

function convertSizeToScale(t)
	for i,v in pairs(t) do
		if v:IsA"BasePart" then
			if v:findFirstChild"Mesh" then
				
				if not v.Size == Vector3.new(0.2, 0.2, 0.2) then
					local vm=v.Mesh
					local vsize=v.Size
					local vscale=vm.Scale
					
					local percx=vsize.X/vscale.X
					local percy=vsize.Y/vscale.Y
					local percz=vsize.Z/vscale.Z		
					
					local vtotalsize=Vector3.new(0,0,0)
	
					if round(v.Size.X*10)/10 ~= 0.2 then
						print(v.Name, v.Size.X)
						vtotalsize = vtotalsize + Vector3.new(percx * 5, 0, 0)
					else
						vtotalsize = vtotalsize + Vector3.new(vm.Scale.X, 0, 0)
					end		
					if round(v.Size.Y*10)/10 ~= 0.2 then
						vtotalsize = vtotalsize + Vector3.new(0, percy * 5, 0)
					else
						vtotalsize = vtotalsize + Vector3.new(0, vm.Scale.Y, 0)
					end	
					if round(v.Size.Z*10)/10 ~= 0.2 then
						vtotalsize = vtotalsize + Vector3.new(0, 0, percz * 5)
					else
						vtotalsize = vtotalsize + Vector3.new(0, 0, vm.Scale.Z)
					end	
						
					local prevc=v.CFrame	
		
					v.Size=Vector3.new(0.2,0.2,0.2)
					v.CFrame=prevc
					vm.Scale=vtotalsize
				end
				
			end
		end		
	end
end

function weld(modelgroup,anchored,cancollide)
	local parts,last = {}
	local function scan(parent)
		for _,v in pairs(parent:GetChildren()) do
			if (v:IsA("BasePart")) then
				if (last) then
					local w = Instance.new("Weld")
					w.Name = ("Weld")
					w.Part0,w.Part1 = last,v
					w.C0 = last.CFrame:inverse()
					w.C1 = v.CFrame:inverse()
					w.Parent = last
				end
				last = v
				table.insert(parts,v)
			end
			scan(v)
		end
	end
	scan(modelgroup)
	for _,v in pairs(parts) do
		v.Anchored=anchored
		v.CanCollide=cancollide
	end
end

wait(1)
for i, v in pairs (script.Parent:GetChildren()) do
	if v:FindFirstChild("Weld") then
		v.Weld:Destroy()
	end
end
convertSizeToScale(parts_table)
weld(script.Parent,true,false)


