Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Remove duplicate objects in a model?

Asked by
Dummiez 360 Moderation Voter
10 years ago

Best way to remove an object with a duplicate name in a model?

Say I have 5 Parts in ModelValues, named:

abc, abc, dba, ddd, ddd

local list = game.ReplicatedStorage.ModelValues:GetChildren()
local filter = {}
local res = {}

for _,v in ipairs(list) do
    if (not filter[v.Name]) then
        res[#res+1] = v.Name
        filter[v.Name] = true
    else
        v:Destroy()
    end
end  

The output returns:

abc, dba, ddd

Answer this question