Still have questions? Join our Discord server and get real time help.
0

# What is wrong with my destroy everything with whitelist function?

local function DestroyAllWithWhitelist(Children,Table)
for i,v in pairs(Children) do
for k,d in pairs(Table) do
if v.Name ~= d then
v:Destroy()
end

end
end
end

DestroyAllWithWhitelist(game.ServerStorage:GetChildren(),{'Fire',"Part",})



it does not work for some reason does anyone know why?

1
Hey not trying to be rude but, people has been answering your previous problems, wouldn't it be nice if you at least respond to them or give them an answer mark? Azure_Kite 688 — 5mo
0
I wish so too. SoftlockedUnderZero 586 — 5mo
0
are you trying to destroy something if it's name does not exist in the whitelist? kisty1 111 — 5mo

0
Edited 5 months ago
local DestroyAllWithWhitelist = function(Entity, Tab) -- Args
for _,obj in next, Entity do -- Iterating through entity
for _,tab in next, Tab do -- Iterating through whitelist table
if obj.Name == tab then -- if matching to entity in whitelist table
obj:Destroy() -- destroys the matching entity.
end
end
end
end

DestroyAllWithWhitelist(workspace.Baseplate:GetChildren(), {'Fire', 'Part'})


Learn from this, goodbye.

-1
Edited 5 months ago

Well here's what the script thinks.

As it runs through the objects destroying them one by one. In the second for loop, comes across a part named "Fire". So since the name of the part is named "Fire" it does not destroy it. However, on the second key/index, it comes across a string called "Part". Since the name of the part is named "Fire" and not "Part" it gets destroyed.

I would consider

--// Assume this is in the first for loop scope.
local Found_Value=table.find(Table,v.Name);