Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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?

3 comments

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?

0

I wish so too.

0

are you trying to destroy something if it's name does not exist in the whitelist?

2 answers

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.

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);
if not Found_Value then
	v:Destroy()
end;

This discussion is preserved as it was. New answers, comments, and votes are closed.