Toggle button fails to work

Hello! I am making a toggle button that toggles all the gui’s. Problem is; none of them won’t be visible. On top of that, no errors print in console.

Code:

local Main = script.Parent.Parent
local visible = false

for i,v in ipairs(require(Main:WaitForChild("Whitelist")).wl) do
	if game.Players.LocalPlayer.UserId == v then
		if visible == false then
			visible = true
			for _, u in pairs(Main:GetDescendants()) do
				if (not u.ClassName == "Folder" or not u.ClassName == "ModuleScript" or not u.ClassName == "LocalScript" or not u.ClassName == "Script" and u.Name ~= "Tog") then
					u.uisible = true
				end
			end
		else
			visible = false
			for _, u in pairs(Main:GetDescendants()) do
				if (not u.ClassName == "Folder" or not u.ClassName == "ModuleScript" or not u.ClassName == "LocalScript" or not u.ClassName == "Script" and u.Name ~= "Tog") then
					u.uisible = false
				end
			end
		end
	end
end

Ideas?

Your issue might be with the typo of “uisible” instead of Visible

2 Likes

A good thought, but since this is not a pcall() the non-error thing concerns me related to your response.

Most likely a syntax error or another error would have popped up in the output.

Fixed that; should’ve worked. But it doesn’t… No errors in the console still.

New Code:

local Main = script.Parent.Parent
local visible = false

for i,v in ipairs(require(Main:WaitForChild("Whitelist")).wl) do
	if game.Players.LocalPlayer.UserId == v then
		if visible == false then
			visible = true
			for _, u in pairs(Main:GetDescendants()) do
				if (not u.ClassName == "Folder" or not u.ClassName == "ModuleScript" or not u.ClassName == "LocalScript" or not u.ClassName == "Script" and u.Name ~= "Tog") then
					u.Visible = true
				end
			end
		else
			visible = false
			for _, u in pairs(Main:GetDescendants()) do
				if (not u.ClassName == "Folder" or not u.ClassName == "ModuleScript" or not u.ClassName == "LocalScript" or not u.ClassName == "Script" and u.Name ~= "Tog") then
					u.Visible = false
				end
			end
		end
	end
end

Seems to be working properly for me
Are the values in Whitelist.wl numbers?

If it isn’t that, could you try adding prints in-between to check at what point the script stops?

“Wl” is a table with UserID’s.

I’ll try print debugging

Just tried it; it got through all the lines. Visible part isn’t working for some reason.
image

Is Parent GUI folder disabled?

1 Like

The ScreenGUI is usually disabled by default. The whitelist system goes through and detects if the player is whitelisted, if so, it enables the ScreenGUI. Which in this scenario, it did. I see the toggle button.

Could you show how your gui is structured in the explorer?

image

1 Like

I have attempted to rewrite the for loops, still doesn’t work. Here is the new code;

local Main = script.Parent.Parent
local visible = false

script.Parent.MouseButton1Click:Connect(function()
for i,v in ipairs(require(Main:WaitForChild("Whitelist")).wl) do
	if game.Players.LocalPlayer.UserId == v then
		if visible == false then
				visible = true
			for _, u in pairs(Main:GetDescendants()) do
				if (u.ClassName == "Frame" or u.ClassName == "TextButton" or u.ClassName == "TextLabel" and u.Name ~= "Tog") then
					u.Visible = true
				end
			end
		else
				visible = false
			for _, u in pairs(Main:GetDescendants()) do
				if (u.ClassName == "Frame" or u.ClassName == "TextButton" or u.ClassName == "TextLabel" and u.Name ~= "Tog") then
					u.Visible = false
				end
			end
		end
	end
end)

Might be the way you write the if statements, try putting the ors together and separate the and

if (u.ClassName == "Frame" or u.ClassName == "TextButton" or u.ClassName == "TextLabel") and u.Name ~= "Tog" then