So, I have a table and I have ui’s. What the system does is if the ui’s text is found more than 1 time it adds the ui to the table. Now what I want it to do is only remove one ui that was found more than 1 time. I did object (which is q in this script) :Destroy() and it destroyed all of the ui’s. How could I make it only destroy the one found more than once?
task.spawn(function()
while task.wait(1) do
for i,q in pairs(VehicleScrollingFrame:GetChildren()) do
if q:IsA("ImageLabel") then
table.sort(CurrentCars)
print(CurrentCars)
local strings = 0
for index,v in ipairs(CurrentCars) do
if CurrentCars[index + 1] == v then
q:Destroy()
end
end
end
end
end
end)
the put a break in the initial if statement at the end after for loop has been done
if q:IsA("ImageLabel") then
table.sort(CurrentCars)
print(CurrentCars)
local strings = 0
for index,v in ipairs(CurrentCars) do
if CurrentCars[index + 1] == v then
q:Destroy()
end
end
break****************
end
if q:IsA("ImageLabel") then
table.sort(CurrentCars)
print(CurrentCars)
local strings = 0
for index,v in ipairs(CurrentCars) do
if CurrentCars[index + 1] == v then
q:Destroy()
break****************
end
end
end
Im gonna be honest, I’m a little confused by your code,
when added a break after q:destroy() it still destroys everything, this shouldve been the place to put a break statement so you could move on to the next q object.
Do you really need the while loop? once this code executes, it should remove any duplicates.
You could also just insert the object you want to keep into a table and then if table.find() the object within said table then continue for loop, else destroy
Every one second it will destroy a car, that is why in the video you see that every 1 second a car disappears, also update the destroy to be like this (because you want it to break as soon as it destroys, because with the code before there was a risk of destroying more than one):
if q:IsA("ImageLabel") then
table.sort(CurrentCars)
print(CurrentCars)
local strings = 0
for index,v in ipairs(CurrentCars) do
if CurrentCars[index + 1] == v then
q:Destroy()
break****************
end
end
break****************
end
task.spawn(function()
while task.wait(1) do
for i,q in pairs(VehicleScrollingFrame:GetChildren()) do
if q:IsA("ImageLabel") then
table.sort(CurrentCars)
print(CurrentCars)
local strings = 0
local found = 0
for index,v in ipairs(CurrentCars) do
if CurrentCars[index + 1] == v then
if found == 0 then found += 1
else q:Destroy() end
end
end
end
end
end
end)
task.spawn(function()
while task.wait(1) do
for i,q in pairs(VehicleScrollingFrame:GetChildren()) do
if q:IsA("ImageLabel") then
print(CurrentCars)
local found = 0
for _,v in ipairs(CurrentCars) do
for _,v2 in ipairs(CurrentCars) do
if v2 == v then
if found == 0 then found += 1
else q:Destroy() end
end
end
end
end
end
end
end)
Try that, also why are you looping in vehicle scrolling frame and then looping in the table, you don’t modify the table then that means it will keep deleting.