Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why aren't my UI's enabling?

I have code that will run if you click a red button and then it closes some GUIs. When I click the button to disable it, it works and makes them disabled but when I try to enable them again, it does nothing. Any way to fix this? Sorry if this is easy to fix, I'm not that good at scripting and I didn't quite latch on to it.

Anyway, here is the code:

local playergui = game.Players.LocalPlayer.PlayerGui
local XButton = script.Parent
local PositionGui = playergui.PositionGui
local PositionGui2 = playergui.PositionGui2
local SpeedGui1 = playergui.SpeedGui1
local SpeedGui2 = playergui.SpeedGui2
local SpeedGui3 = playergui.SpeedGui3
local SpeedVelocityGui1 = playergui.SpeedVelocityGui1
local SpeedVelocityGui2 = playergui.SpeedVelocityGui2
local enabled = true

XButton.Activated:Connect(function(clicked)
	if clicked and PositionGui.Enabled and PositionGui2.Enabled and SpeedGui1.Enabled and SpeedGui2.Enabled and SpeedGui3.Enabled and SpeedVelocityGui1.Enabled and SpeedVelocityGui2.Enabled and enabled == true then
		PositionGui.Enabled = false
		PositionGui2.Enabled = false
		SpeedGui1.Enabled = false
		SpeedGui2.Enabled = false
		SpeedGui3.Enabled = false
		SpeedVelocityGui1.Enabled = false
		SpeedVelocityGui2.Enabled = false
		enabled = false
		script.Parent.BackgroundColor3 = Color3.fromRGB(17, 255, 0)
		print("You clicked the button to deactivate the guis")
	end	
		
XButton.Activated:Connect(function(clicked2)
			
	if clicked2 and PositionGui.Enabled == false and PositionGui2.Enabled == false and SpeedGui1.Enabled == false and SpeedGui2.Enabled == false and SpeedGui3.Enabled == false and SpeedVelocityGui1.Enabled == false and SpeedVelocityGui2.Enabled == false and enabled == false then
		print("Passed second if")
		PositionGui.Enabled = true
		PositionGui2.Enabled = true
		SpeedGui1.Enabled = true
		SpeedGui2.Enabled = true
		SpeedGui3.Enabled = true
		SpeedVelocityGui1.Enabled = true
		SpeedVelocityGui2.Enabled = true
		enabled = true
		script.Parent.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
		print("ran code")
		end
	end)
end)

1 comment

0

Try the new changes

1 answer

✓ Accepted answer

The script its very long, but there is a way to fix it! Using tables. As you can see, most of the objects children are inside the playergui. So i would recommend to use function :GetChildren() which creates a table containing all the children of a parent.

Use the following code:

local playergui = game.Players.LocalPlayer.PlayerGui
local XButton = script.Parent
local Guis = playergui:GetChildren() --Here it gets all guis inside a table

XButton.MouseButton1Click:Connect(function() --Fires when a player clicks the button
      for i, v in pairs(Guis) do --Sets a loop for all the guis, v is the children, and i is the loops
           if v:IsA("ScreenGui") and v.Name ~= "XButtonGui" then -- If my children is a ScreenGui type then...
               if v.Enabled ==  then --We dont need enabled variable since it detects it already
                       v.Enabled = false
                       script.Parent.BackgroundColor3 = Color3.fromRGB(17, 255, 0)
           	        print("You clicked the button to deactivate the guis")
               else  --If the guis are not enabled
                       v.Enabled = true
                      script.Parent.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
	               print("ran code")
          end
     end
end)

Yep. That easy. Tell me if i got something wrong

3 comments

0

Sorry if the script is disoredered

0

Your code works and all that but It also disables the x button.

0

Let me fix it

This discussion is preserved as it was. New answers, comments, and votes are closed.