Gui elements not being invisible with the current code

  1. What do I want to achieve?
    I want to make my Gui buttons working basically but it doesn’t go to 31st line.
  2. What is the issue?
    Issue is:
    left blank intentionally - YouTube
    (Sorry for small screen it’s something with Nvidia Optimus and it does only run the game itself.)
    Basically it makes Float window visible when I click ClassicSword as I wanted but it doesn’t make anything invisible.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I asked other people in communication platforms, looked for solutions on the Developer Hub and added prints, it seems like last if not function is never running and everything is going in else part.

My explorer:
image
My script:

local frame = script.Parent.Parent
local menus = frame.Parent:FindFirstChild("Menus")
local MainSettings = frame:FindFirstChild("MainSettings")
local ClassicSwordSettings = frame:FindFirstChild("ClassicSword")
local allFrames = frame:GetChildren()
local allMenus = menus:GetChildren()

local function filter(Table, FilterItem)
	if not type(FilterItem) == 'string' then
		FilterItem = tostring(FilterItem)
	end
	if type(Table) == 'table' then
		for i, v in pairs(Table) do
			if v.ClassName == FilterItem then
				Table[i] = nil
				return Table
			end
		end
	else
		assert(false, "This is not a table.")
	end
end

filter(allFrames, 'Folder')
filter(allMenus, 'LocalScript')

for _, v1 in pairs (allMenus) do
	v1.MouseButton1Click:Connect(function()
		for _, v2 in pairs (allFrames) do
			if not v2.Name == v1.Name then
				v2.Visible = false --This never happens.
			else
				v2.Visible = true
			end
		end
 	end)
end

Does not give any errors.

Since the not operator has higher precedence over == you are doing if false == 'string' then

So just use the ~= operator:

if type(FilterItem) ~= "string" then

Thanks for replying. I changed it but same issue continues.

try outputting the tables after running the filter function, like print(unpack(allFrames)) and print(unpack(allMenus)), maybe they aren’t being setup correctly

you could also print v2 and v1 to check what frames are being checked in both for loops

I did and it seems like filter is running quite well. But it was outputting one nil and I removed it with adding

if v1 == nil then return end

And same thing with v2 when they begin checking. Still issue continues.

Check the explorer ingame, maybe you have 2 of this gui shown
and where are you putting if v1 is nil return? if you put it in one of for loops for the MouseClick, it’ll stop the loop from continuing to the next items

for _, v1 in pairs (allMenus) do
	if v1 == nil then return end
	v1.MouseButton1Click:Connect(function()
		for _, v2 in pairs (allFrames) do
			if v2 == nil then return end
			if not v2.Name == v1.Name then
				v2.Visible = false
			else
				v2.Visible = true
			end
		end
 	end)
end

And no, one of their Visible is false as you can see on the video.

try changing if not v2.Name == v1.Name then to if not (v2.Name == v1.Name) then or if v2.Name ~= v1.Name then because incapaxx said that not has a higher precedence over ==

1 Like

Weird but… Works! Thanks for letting me know this, I’ll mark both as solution. (I just found out I can’t so I’ll just drop a like.)

Instead of reinventing the wheel, use ~=.

Thanks for your kind words but I’ve already done as you can see. Also aren’t if not and ~= the same thing?

No, ~= is equivalent to ‘is not equal to’, whereas ‘not’ is defined as ‘not’.
Not is a characteristic of boolean logic such that:

if not (condition_1 and condition_2)
means the same as
if (not condition_1) or (not condition_2)

So you can achieve a statement where they are equivalent like:
if not (type(FilterItem) == 'string' ) and
if type(FilterItem)~='string'

but not without parenthesis, not takes preference so:
if not type(FilterItem) == 'string' becomes
if false == 'string'

Its like the order of operations in math, but with words; ‘not’ is like a negative sign, and ~= is a conditional equality conditional stating two items are not equal.

1 Like