local a={"\080\097\114\116","\087\101\100\103\101\080\097\114\116";"\084\114\117\115\115\080\097\114\116";"\077\111\100\101\108","\083\101\097\116","\086\101\104\105\099\108\101\083\101\097\116"}function isValidClass(x)local B=x.className for x=1,#a,1 do if B==a[x]then return true end end return false end function isValidPart(a)if isValidClass(a)==true then return a end return nil end function retriveParts(a)if isValidPart(a)and a.className~="\077\111\100\101\108"then WorkSpaceObjects[WSONum]=a WSONum=WSONum+1 else local x=a:GetChildren()for a=1,#x,1 do local B=isValidPart(x[a])if B~=nil then if B.className=="\077\111\100\101\108"then retriveParts(B)else if B.Anchored==false then WorkSpaceObjects[WSONum]=B WSONum=WSONum+1 end end end end end end function RemoveBits(a)if isValidPart(a)and a.className~="\077\111\100\101\108"then for x=1,#WorkSpaceObjects,1 do if a==WorkSpaceObjects[x]then table.remove(WorkSpaceObjects,x)WSONum=WSONum-1 end end else local x=a:GetChildren()for a=1,#x,1 do local B=x[a]if B.className=="\077\111\100\101\108"then RemoveBits(B)else for a=1,#WorkSpaceObjects,1 do if B==WorkSpaceObjects[a]then table.remove(WorkSpaceObjects,a)WSONum=WSONum-1 end end end end end end retriveParts(game.Workspace)game.Workspace.ChildAdded:connect(retriveParts)game.Workspace.ChildRemoved:connect(RemoveBits)

local ValidClassNames = {"Part","WedgePart","TrussPart","Model","Seat","VehicleSeat"}
function isValidClass(part)
	local CN = part.className 
	for i=1,#ValidClassNames do
		if(CN == ValidClassNames[i]) then
			return true
		end
	end
	return false
end
function isValidPart(part)	-- returns className if its a part or model otherwise returns nil
	if isValidClass(part) == true then
		return part
	end
   return nil -- not a part or an model
end

function retriveParts(model) -- main function for retriving all the parts of a model and loading them into a table
	if(isValidPart(model) and model.className ~= "Model") then
			WorkSpaceObjects[WSONum] = model;
			WSONum = WSONum + 1;
	else
		local raw_model = model:GetChildren()
		for i=1,#raw_model do
			local part = isValidPart(raw_model[i])
			if(part ~= nil) then
				if(part.className == "Model") then
					retriveParts(part);
				else
					if(part.Anchored == false) then
						--if(part:findFirstChild("TAG") == nil) then
						--	Tag = Instance.new("ObjectValue")
						--	Tag.Parent = part
						--	Tag.Name = "TAG"
							WorkSpaceObjects[WSONum] = part;
							WSONum = WSONum + 1;
						--end
					end
				end
			end
		end
	end
end
function RemoveBits(model) -- Function for removing bits from our global table as they dont exist in the workspace anymore
	if(isValidPart(model) and model.className ~= "Model") then
		for i=1,#WorkSpaceObjects	do
			if(model == WorkSpaceObjects[i]) then
				table.remove(WorkSpaceObjects,i)
				WSONum = WSONum -1
			end
		end
	else
		local raw_model = model:GetChildren()
		for i=1,#raw_model do
			local part = raw_model[i]
			if(part.className == "Model") then
				RemoveBits(part);
			else
				for i=1,#WorkSpaceObjects	do
					if(part == WorkSpaceObjects[i]) then
						table.remove(WorkSpaceObjects,i)
						WSONum = WSONum -1
					end
				end
			end
		end
	end
end

retriveParts(game.Workspace); -- call our retreiver
game.Workspace.ChildAdded:connect(retriveParts)-- just encase any new objects get added to the game
game.Workspace.ChildRemoved:connect(RemoveBits)