-
What do you want to achieve?
Basically I need to delete duplicate parts on my map (Parts with exactly the same position size and color)
-
What is the issue?
Theres thousands of parts so it takes a super long time going through each of them, like a super long time, I was wondering if there was anyway to speed up the process?
edit: i forgot to add the firstpart.position == secondpart.position and stuff so dont mind it being missing
local partstoclean = workspace:GetDescendants()
local count = 0
for _, firstpart in partstoclean do
if firstpart:IsA("BasePart") then
for _, secondpart in partstoclean do
if secondpart:IsA("BasePart") then
count += 1
print("Destroyed "..count.." dupes")
secondpart:Destroy()
table.remove(partstoclean, table.find(partstoclean, secondpart))
break
end
task.wait()
end
end
task.wait()
end
4 Likes
I don’t think task.wait() is necessary since your not using a while true do loop.
2 Likes
Why not just delete them manually? You can create a function and use task.spawn on that function to delete them fast.
2 Likes
I added the task.wait() because before before when i had no task.wait(), it crashed the second i ran the script in command bar
2 Likes
Too many to delete manually, but yea ill try the task.spawn thing
2 Likes
Nope it wouldnt because i cant manually select all of the thousands of copies, thanks for the suggestion tho
2 Likes
you could make this code easier on your computer by adding a for loop before the deletion step, and a task.wait(1) right after, i would suggest waiting at least 3 seconds (no parts are destroyed until the task scheduler loops, if you dont get any frames for three seconds, you might crash) every 100 deleted parts:
local saved = {}
local start = tick()
local items = 0
for index, object in pairs (workspace:GetDescendants()) do
if object:IsA(“BasePart”) then
for batch = 1,100 do
for index2, object2 in pairs (saved) do
if object.CFrame == object2.CFrame and object.Size == object2.Size then
object:Destroy()
items = items + 1
continue
end
end
end
table.insert(saved, object)
task.wait(3)
end
end
local delta = tick() - start
print("Number of items: ", items)
print("Time elapsed: ", delta)