This is my first bit of useful complex code, haven’t really done anything but change the color of a brick so far in lua. My employment as a 3D modeler has been more then enough lol. Anyway builders rejoice this is a tool i made for fast grouping of any model
Simply drop a script with this code in it, into the structure’s main model or folder. Any parts, unions, or meshes you want sorted by color put into a folder called “SortParts” anything not in that folder will not be touched.
Hit Run on the game
Copy the structure
Stop the game
Paste the structure.
Or you can delete lines 50, 51 and have it name the folders by colors instead.
Its a really simple tool that i can see being used in applications like city builds where the same building will have multiple color variations, or just general grouping to not get on your co-developers nerves.
--NOTE DELETE LINES 50,51 TO GROUP BY COLOR NAME INSTEAD OF NUMBER
local AllParts = script.Parent:GetChildren()
local Structure = script.Parent
local Sort = script.Parent.SortParts:GetChildren()
local Windows
local ColorName
local Folder
local FolderNum = 0
local Temp
local Group
-- Window Organization
Windows = Instance.new("Model")
Windows.Parent = Structure.SortParts
Windows.Name = "Windows"
for i,v in pairs(AllParts) do
if v.Name == "Window" then
v.Parent = Windows
end
end
-- Dummy Folder Creation
Temp = Instance.new("Folder")
Temp.Name = "Temp"
Temp.Parent = Structure
-- Sort, and Organize
Sort = Sort
for i,v in pairs(Sort) do
if v:IsA("Part") or v:IsA("UnionOperation") or v:IsA("MeshPart") then
ColorName = v.BrickColor.Name
if not script.Parent.Temp:FindFirstChild(ColorName) then
Folder = Instance.new("Model")
Folder.Parent = Temp
Folder.Name = ColorName
v.Parent = Folder
else
v.Parent = script.Parent.Temp:FindFirstChild(ColorName)
end
end
end
-- Process Temp Folder
Group = Temp:GetChildren()
for i, v in pairs(Group) do
FolderNum = FolderNum + 1
v.Name = tostring(FolderNum)
v.Parent = Structure
end
-- CleanUp
Structure.Temp:Destroy()
Structure.SortParts:Destroy()
warn(tostring(script.Parent.Name).." Was Successfully Grouped, COPY stucture and click STOP")
script:Destroy()