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

Script is destroying objects when it shouldn't be?

Asked by 8 years ago

Not the complete code, but this script shouldn't be destroying the objects named "Scrollbar" and "Title" but it's doing it anyway.

for i, v in pairs(Objects:GetChildren()) do
    if ((v.Name ~= "Scrollbar") or (v.Name ~= "Title")) then
        v:Destroy()
        print("Destroyed: " .. v.Name)
    end
end

Output: Destroyed: Scrollbar Destroyed: Title

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

Every name is either "not Scrollbar" or "not Title".

You mean and: it must be neither Scrollbar nor "Title".

Another way to think of it:

if v.Name == "Scrollbar" or v.Name == "Title" then
    -- I want to keep it
else
    -- I want to delete it
end

To flip that, you can add a not ( ... to the whole condition:

if not (v.Name == "Scrollbar" or v.Name == "Title") then

De Morgan's laws tells us this is:

if v.Name ~= "Scrollbar" and v.Name ~= "Title" then
0
Thank you! DangCoolIsReal 32 — 8y
Ad

Answer this question