Does anyone here have a good script that can remove duplicate parts based on size, position and orientation?
Like if 2 are duped in a single spot, it would delete 1 dupe, etc?
Does anyone here have a good script that can remove duplicate parts based on size, position and orientation?
Like if 2 are duped in a single spot, it would delete 1 dupe, etc?
Iâm assuming youâd want to delete duplicates that have the same position as eachother?
local num = 0
local Parts = {
}
for i, v in pairs(game.Workspace:GetDescendants()) do
if v:IsA("BasePart") then
num = num + 1
table.insert(Parts, num, v.Position)
for n, k in pairs(Parts) do
if k == v.Position then
v:Destroy()
end
end
end
end
You can swap out the âPositionâ property with any other property, for example you want to have only one part with a certain orientation you change the âpositionâ to âorientationâ
It may be more prudent to ask why there would be duplicate parts in the same position, and fix whatever is duplicating parts. We can often give you a much higher-quality answer if you also include your use-case.
I thought basepart included all: parts, meshparts and unions? i guess i was wrong iâll edit my script
We just have a huge map with trees and train tracks placed and wanted to confirm no parts of exact size and shape and position are not accidentally CTRL+D and not ever dragged from position.
Youâre right. BasePart accounts for them all⌠My badâŚ
I edited my script above to fit your description, check if that would work in a studio run.
Didnât do anything. Part count remained the same.
i wasnât thinking when i wrote that cause that code is absolute garbage
local num = 0
local Parts = {
}
for i, v in pairs(game.Workspace:GetDescendants()) do
if v:IsA("BasePart") then
num = num + 1
table.insert(Parts, num, v.Position)
end
end
for i, v in pairs(game.Workspace:GetDescendants()) do
if v:IsA("BasePart") then
for n, k in pairs(Parts) do
if k == v.Position and not k == v then
v:Destroy()
end
end
end
end
Just a really quick fix but it should do the job assuming you dont use it during runtime
Lost 90% of my City progress, Thanks.
I hope ill find a back up or am able to revert to a very recent version,
this might just have been the better choice
You can quite easily revert if you have at any point published to Roblox, autosaves are also usually created every time you play-test it.
yeah i figured it out already, thanks
My fault for that, I forgot one key condition.
if k == v.Position and not k == v then
v:Destroy()
end
You should be able to revert from âversion historyâ or sometimes CTRL + Z works too.
Again, my apologies and thanks for pointing it out.
Youve tried to elp so i cannot be mad at you, you cannot CTRL+Z / Undo for loop actions, instead you would need to use some sort of manual action saver that roblox has, not sure what that is called but you have to manually save the for loop as an undo-able action.