Is there a more efficient way to do this?

directory.Open.MouseButton1Click:Connect(function()
	for i,v in pairs(directory:GetChildren()) do
		if v.Name == "Open" then
			--do nothing
		elseif
			v:IsA("LocalScript") then
				-- do nothing
		else
			v.Visible = true
		end
	end
end)
2 Likes

Youre running multiple ifs and not doing anything with them.

Just do

--Typed on mobile

if v.Name ~= "Open" and not v:IsA("LocalScript") then
   v.Visible = true
end
6 Likes

Critiquing the consistency here, using ~= and not in the same line. I would change it to

if not(v.Name == "Open" or v:IsA("LocalScript")) then
1 Like

~= is comparing strings, not is a boolean comparator. Boat was completely correct :slight_smile:

1 Like

Though that works I think that he was saying from a readability standpoint it’s better to do this:

not(v.Name=="Open" or v:IsA("LocalScript"))

Than it is to be doing this:

(not v.Name == "Open" and not v:IsA("LocalScript"))
2 Likes

I don’t entirely agree with how you phrased that.
As ~= returns either true or false I would consider stringA ~= stringB to effectively be a boolean in and of itself, and so the way he’s written is is equivalent to

if not booleanA and not booleanB then

which would be written better as

if not(booleanA or booleanB) then
1 Like

You all make valid points. However, any performance differences are miniscule, and this is just a readability and style issue.

Everyone can simply go with what works for them. I still like the way I wrote it, because it reads very easily (for me).

3 Likes

If you prefer it that way, then fair enough - I was just proposing best practices for the forums

1 Like

You can’t compare strings with “not”

I never said you could?
I was saying that stringA ~= stringB is the same as not(stringA == stringB), and was giving styling practices based off of that

I see what you meant. My bad.
Are you sure that you can use distribute property here? I can’t recall, haha

I’m afraid I don’t understand your question