-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathautoNamer.luau
43 lines (37 loc) · 1.12 KB
/
autoNamer.luau
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local prefix, reverse, direction, detectOtherSize, otherSidePrefix, otherDifference = "", true, "X", false, "L", 0.2
local existingCount = 0
local parts = game.Selection:Get()
if #parts == 0 then
return
end
for _, v in pairs(parts) do
if v:IsA("BasePart") == false then
error("Only parts are allowed")
end
end
local basePosition = parts[1].Position
if detectOtherSize ~= false then
local otherParts = {}
for _, v in pairs(parts) do
if math.abs(v.Position[detectOtherSize] - basePosition[detectOtherSize]) <= otherDifference then
table.insert(otherParts, v)
end
end
table.sort(otherParts, function(a, b)
return if reverse == false
then a.Position[direction] < b.Position[direction]
else a.Position[direction] > b.Position[direction]
end)
for i, v in pairs(otherParts) do
v.Name = otherSidePrefix .. i + existingCount
table.remove(parts, table.find(parts, v))
end
end
table.sort(parts, function(a, b)
return if reverse == false
then a.Position[direction] < b.Position[direction]
else a.Position[direction] > b.Position[direction]
end)
for i, v in pairs(parts) do
v.Name = prefix .. i + existingCount
end