You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Soo what i want to do is going through a scrollframe and find duplicated frames with the same name and delete all the copys and keep 1 single
What is the issue? Include screenshots / videos if possible!
I dont know how to do it and i didnt find anything revelant in devforum
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
This is what i tried but idk what to do next
local folder = script.Parent
local gui = folder.Parent
local main = gui:WaitForChild("MainGui")
local screens_f = main:WaitForChild("Screens")
local c_frame = screens_f:WaitForChild("Cosmetics")
local scrollframe = c_frame:WaitForChild("MainCosmeticsScreen")
local function checkduplicate()
for _, cosm in pairs(scrollframe:GetChildren()) do
local children = {
}
if cosm:IsA("Frame") then
end
end
end
You can keep track of the names you’ve seen, then you can destroy any further encountered instances of it.
local folder = script.Parent
local gui = folder.Parent
local main = gui:WaitForChild("MainGui")
local screens_f = main:WaitForChild("Screens")
local c_frame = screens_f:WaitForChild("Cosmetics")
local scrollframe = c_frame:WaitForChild("MainCosmeticsScreen")
local function checkduplicate()
local seen = {}
for _, cosm in scrollframe:GetChildren() do
if not cosm:IsA("Frame") then
continue
end
local cosmName = cosm.Name
if table.find(seen, cosmName) then
cosm:Destroy()
continue
end
table.insert(seen, cosmName)
end
end
What @nowodev said is correct usage and should work fine, but for a case like this I would recommend using table[value] = true rather than table.insert and table.find. Really if there are a lot of frames.
Mainly because table.find(seen, name) is O(n) time complexity, but using a dictionary (seen[name] = true) is O(1).
local folder = script.Parent
local gui = folder.Parent
local main = gui:WaitForChild("MainGui")
local screens_f = main:WaitForChild("Screens")
local c_frame = screens_f:WaitForChild("Cosmetics")
local scrollframe = c_frame:WaitForChild("MainCosmeticsScreen")
local function checkduplicate()
local seen = {}
for _, cosm in pairs(scrollframe:GetChildren()) do
if cosm:IsA("Frame") then
if seen[cosm.Name] then
cosm:Destroy()
else
seen[cosm.Name] = true
end
end
end
end
checkduplicate()