I want to know how you could make parts go close to certain other parts in an array like a square using a script.
I want to know how you go from this:
to this:
Any help would be appreciated.
I want to know how you could make parts go close to certain other parts in an array like a square using a script.
I want to know how you go from this:
Any help would be appreciated.
Where would you want the parts to be relative to their old positions? Does it not matter? Should they be in the middle of the old positions?
It doesn’t matter I just want them to be close to eachother
SORT_POINT
is where the parts start from.
PADDING
is the distance between each part (discluding automatic distancing by size).
Use the sort
function on the array of parts you want to sort.
local SORT_POINT = Vector3.new(0, 1, 0)
local PADDING = 0.2
local function sort(parts: { BasePart })
local length = #parts
local root = math.sqrt(length)
local xLength = math.ceil(root) - 1
local zLength = math.floor(root) - 1
local i = 1
for x = 0, xLength do
for z = 0, zLength do
local part = parts[i]
part.Position = SORT_POINT + Vector3.new(x * (part.Size.X + PADDING), 0, z * (part.Size.Z + PADDING))
i += 1
end
end
end
thanks it works. I couldn’t figure this out but you helped me
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.