ViewPortFrame collection

Long story short, I’m working on methods of VPF at the moment.
The plan is to copy everything from Workspace that is not: Descendant of any model named Exterior; OR a part of a Player.

Currently, this is what I have and it doesn’t look the best. Can anyone suggest or assist me further?

for _,i in pairs (game:GetService("Workspace"):GetDescendants()) do
		if i:IsA("BasePart") then
			if i.Name == "Terrain" then
			else
				if i.Parent.Name == "Exterior" or i.Parent.Parent.Name == "Exterior" then
				else
				for _,z in pairs (Character:GetDescendants()) do
					if i == z then else
					local c = i:Clone()
					c.Parent = world1
					end
				end
				end
			end
		end
	end
1 Like

(Note that #help-and-feedback:code-review is a better place to post this in)

Instead of looping through every Descendant and check if it’s parented to something you don’t want, loop through every Child of workspace, check if it’s something you want and if so loop through its Descendants.

General issues

Using game:GetService("Workspace") is not cook, just use workspace, shorter and more readable.

Instead of doing

if x == y then
else
--do stuff
end

Use ~= instead

if x ~= then

end

For example instead of

			if i.Name == "Terrain" then
			else
				if i.Parent.Name == "Exterior" or i.Parent.Parent.Name == "Exterior" then
				else
				for _,z in pairs (Character:GetDescendants()) do
					if i == z then else
					local c = i:Clone()
					c.Parent = world1
					end
				end
				end
			end

Simply do

			if i.Name ~= "Terrain" then
				if i.Parent.Name == "Exterior" or i.Parent.Parent.Name == "Exterior" then
				else
				for _,z in pairs (Character:GetDescendants()) do
					if i == z then else
					local c = i:Clone()
					c.Parent = world1
					end
				end
				end
			end

Checking for Terrain is also useless, because you are checking beforehand if something is a BasePart (unless Terrain is a special part named Terrain)