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

Script is destroying objects when it shouldn't be?

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

✓ Accepted answer

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

1 comment

0

Thank you!

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