Hiding and Showing GUI issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m making a dialogue system in roblox studio, and want to make it so while the dialogue gui is enabled, all other guis are disabled.

  2. What is the issue? Include screenshots / videos if possible!
    When the UI is enabled, the others disappear as scripted, but when I disable it they don’t come back.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried searching on the devforum + documentation.

Current Script:

local IsVisible = false

while wait() do
	if script.Parent.Dialogue.Enabled then
		IsVisible = true
		for _, GUI in script.Parent:GetChildren() do
			if GUI.Name ~= "Dialogue" then
				GUI.Enabled = false
			end
		end
	end
end

if IsVisible and script.Parent.Dialogue.Enabled then
	IsVisible = false
	for _, GUI in script.Parent:GetChildren() do
		if GUI.Name ~= "Dialogue" then
			GUI.Enabled = true
		end
	end
end

Hi, personally I would do something like this:

-- DialogueHandler LocalScript

local Player = game:GetService("Players").LocalPlayer

local DisabledUIs = {}

wait(5)

Player.PlayerGui.Dialogue.Enabled = true

for _, UIs in Player.PlayerGui:GetChildren() do -- This'll get all the ScreenGui elemets under PlayerGui
	if not table.find(DisabledUIs, UIs.Name) and UIs:IsA("ScreenGui") and UIs.Name ~= "Dialogue" then
		table.insert(DisabledUIs, UIs.Name) -- This'll handle duplicate prevention & later re-enabled ones that were disabled
		
		UIs.Enabled = false
	end
end

wait(5)

Player.PlayerGui.Dialogue.Enabled = false

for _, UIs in Player.PlayerGui:GetChildren() do
	if table.find(DisabledUIs, UIs.Name) and UIs:IsA("ScreenGui") and UIs.Name ~= "Dialogue" then
		for Index, Items in pairs(DisabledUIs) do
			if DisabledUIs == UIs.Name then
				table.remove(DisabledUIs, Index)
				break
			end
		end
		
		UIs.Enabled = true
	end
end

Edit: This is assuming the UI items you want to disable are ScreenGui’s under the Player’s PlayerGui, you can also use GetDescendants to filter out more.

there seems no way to exit the while loop, so your second part of code that is outside of the while loop will never get called

Why not use functions?

function ShowUI()
   UIFrame.Visible = true
end

function CloseUI()
   UIFrame.Visible = false
end

OpenUIButton.Activated:Connect(ShowUI)
CloseUIButton.Activated:Connect(CloseUI)

Use task.spawn():

local IsVisible = false
task.spawn(function()
while wait() do
	if script.Parent.Dialogue.Enabled then
		IsVisible = true
		for _, GUI in script.Parent:GetChildren() do
			if GUI.Name ~= "Dialogue" then
				GUI.Enabled = false
			end
		end
	end
end
end)

if IsVisible and script.Parent.Dialogue.Enabled then
	IsVisible = false
	for _, GUI in script.Parent:GetChildren() do
		if GUI.Name ~= "Dialogue" then
			GUI.Enabled = true
		end
	end
end

I don’t recommend you to use while loop to check Dialogue is Enabled. This will significantly increase CPU usage.

Instead, you can update their Gui Visibility when they toggle Dialogue.

1 Like

This.

script.Parent.Dialogue.Changed:Connect(function()
    if script.Parent.Dialogue.Enabled then
    ...

This should work, although I’m not sure whether Enabled works with Changed. Worth a shot though.

Although all of these work quite well, this one will work best for me now that I think about it. Since I’m going to use remote/bindable events, this will let me easily integrate it into my actual dialogue function. Thanks for the help :slight_smile: