Gui's not hiding

Somehow my script doesn’t work, But there’s no error and also half of the gui’s get invisible and the other half doesn’t and after that I can’t click it again, nothing happens. Where did I make a mistake?? Thank you for reading!

local db = true
script.Parent.MouseButton1Click:Connect(function()
	local childr = script.Parent.Parent.Parent.Parent.Parent.Parent.ScreenGui:GetChildren()
	for i, v in pairs(childr) do
		if db == true then
			db = false
			if v:IsA("TextLabel") or v:IsA("TextButton") or v:IsA("Frame") then
				v.Visible = false
			end
			script.Parent.Text = "Show"
		else
			db = true
			if v:IsA("TextLabel") or v:IsA("TextButton") or v:IsA("Frame") then
				v.Visible = true
			end
			script.Parent.Text = "Hide"
		end
	end
end)

These are the gui’s (Only screengui is supposed to be invisible)

Just disable the whole GUI.

local player = game.Players.LocalPlayer

local db = true
script.Parent.MouseButton1Click:Connect(function()
	local gui = player.PlayerGui.ScreenGui
	if db == true then
		db = false
		gui.Enabled = false
		script.Parent.Text = "Show"
	else
		db = true
		gui.Enabled = true
		script.Parent.Text = "Hide"
	end
end)
1 Like

Use ScreenGui.Enabled instead.

local gui = game.Players.LocalPlayer.ScreenGui -- I recommend changing the name of this gui

script.Parent.MouseButton1Click:Connect(function()
	gui.Enabled = not gui.Enabled
    script.Parent.Text = gui.Enabled and "Hide" or "Show"
end)
1 Like

ay much appreciated g much love

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.