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

How to delete everything except these models?

So I am trying to delete everything in workspace that is a model but keeping some of the models. I used names. This is the script I tried before. [All of them dont actually say name, that is just an example]

for i, v in pairs(game.Workspace:GetChildren()) do
if v.ClassName == "Model" then
if v.Name ~= "name" or "name" or "name" or "name" or "name" or "name" or "name" or "name" or "name" or "name" or "name" then
--print(v.Name)
end
end

Could anyone help? Thanks

2 answers

✓ Accepted answer

This is so wrong, between each 'or' you should say if v.Name ~= "name". Like for example:

for i, v in pairs(game.Workspace:GetChildren()) do
	if v.ClassName == "Model" then
		if v.Name ~= "name" or v.Name ~= "name" or v.Name ~= "name" then
		--print(v.Name)
	end
end

Your way of adding ors everywhere isn't very efficient, I think you should use tables instead, as it saves more time, you just need to type a comma then a string, like this:

ignore = {'name','name2','name3'}
for i, v in pairs(game.Workspace:GetChildren()) do
    if v.ClassName == "Model" then
        if isInTable(ignore,v.Name) then
        --print(v.Name)
    end
end
function isInTable(tab,thing)
for i = 1,#tab do
if tab[i] == thing then
return true
end
end
end

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