Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to delete everything except these models?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
Ad
Log in to vote
0
Answered by 6 years ago

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

Answer this question