I have a model full of parts and i want to separate the parts into a “collection”, i want every part of its group to have the same number as its name, or group them all together (however you wanna help me)
i have this script i wrote here already but im no really sure what to do next?
local Model = workspace.Model
local ModelChildrens = Model:GetChildren()
local function GetDistance(FirstPart, SecondPart, Positive)
local Offset = FirstPart.Size.X/2 + SecondPart.Size.X/2
local Position = FirstPart.CFrame:ToWorldSpace(CFrame.new(Positive and Offset or -Offset,0,0)).Position
local Distance = (Position - SecondPart.Position).Magnitude
return Distance
end
for FirstIndex, FirstPart in pairs(ModelChildrens) do
for SecondIndex, SecondPart in pairs(ModelChildrens) do -- Negative Offset
if FirstPart == SecondPart then continue end
if GetDistance(FirstPart, SecondPart, false) < 0.1 then else continue end
end
for SecondIndex, SecondPart in pairs(ModelChildrens) do -- Positive Offset
if FirstPart == SecondPart then continue end
if GetDistance(FirstPart, SecondPart, true) < 0.1 then else continue end
end
end
after a bit of fiddling, i finally found the way to do it.
group = 0
for i,v in pairs(script.Parent.Model:GetChildren()) do
v.Size += Vector3.new(0.1, 0, 0.1)
allowed = true
group = group + 1
a = Instance.new("Model")
a.Name = group
a.Parent = script.Parent.Model
v.Parent = a
currentgroup = a
for ii,vv in pairs(v:GetTouchingParts()) do
if vv ~= v then
if tonumber(vv.Parent.Name) then
currentgroup = vv.Parent
break
else
vv.Parent = a
end
end
end
if currentgroup ~= a then
for i,vvv in pairs(a:GetChildren()) do
vvv.Parent = currentgroup
end
a:Destroy()
group = group - 1
end
v.Size -= Vector3.new(0.1, 0, 0.1)
end
put this script in workspace, and name the model with the parts inside “Model” and this should sort it out for you
edit: not the most efficient code but atleast it works.