Unable to disable GUI via LocalScript

So I have the following LocalScript that simply makes a ScreenGUI object appear and disappear when the button it’s in is pressed.
The object appears as it’s supposed to on the first press, but will not disappear upon subsequent activations.

local b = script.Parent

b.Activated:Connect(function()
	if script.Parent.Parent.Settings.Enabled then
		script.Parent.Parent.Settings.Enabled = 0
	else
		script.Parent.Parent.Settings.Enabled = 1
	end
end)

image Object hierarchy

“Enabled” is a boolean value (true or false) so numbers/integers aren’t compatible with that property.

For example:

script.Parent.Enabled = false -- the GUI isn’t visible no more

Edit: Thanks for marking me as the solution but @Abobora_iluminada‘s response was way more detailed.

3 Likes

Enabled proprety is a boolean (which means use either true or false),
and another way of disabling UI is by changing the visible proprety of any UI object (boolean)

2 Likes

.Enabled is a Boolean value.

Better Code
local Button = script.Parent
local ToOpenGui = Button.Parent.Settings

Button.Activated:Connect(function()
	if ToOpenGui.Enabled == false then
		ToOpenGui.Enabled = true
	elseif ToOpenGui.Enabled == true then
		ToOpenGui.Enabled = false
	end
end)

Instead of GUI objects inside GUI objects, use Frames.
(Frames have .Visible property)

2 Likes

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