How do I make this script more efficient?

i want to group multiple parts with different names into one model, which i have sort-of achieved using the following script:

for i,v in pairs(workspace:GetChildren())do
	if v.Name == "PartA" then
		v.Parent = workspace.Model
	elseif v.Name == "PartB" then
		v.Parent = workspace.Model
	elseif v.Name == "PartC" then
		v.Parent = workspace.Model
	elseif v.Name == "PartD" then
		v.Parent = workspace.Model
	elseif v.Name == "PartE" then
		v.Parent = workspace.model
	end
end

but i want to make this script more efficient, i.e use less lines of code.

i considered using table.find but i have no idea how to implement it into a script like this. are there other ways to reduce the lines of code on this?

You would put this in: Code Review - Developer Forum | Roblox not Scripting Support

ok then i will go there thanks for reminding me

Make everything in a folder

local Folder = workspace.Folder -- reference

for _,v in pairs(Folder:GetChildren()) do -- literate through folder
   v.Parent = workspace.Model -- parent model
end
2 Likes