I have a GUI which I want to open using a button in a different GUI. When said GUI is open (the one which opens the other one) and I press the button nothing happens. Otherwise, the GUI opens even if my boolvalue, Open is set to false. I'm using all LocalScripts by the way.
--Script one local open = game.StarterGui.ScreenGui.KartChoiceGUI.Open local gui = script.Parent if open == true then gui.Visible = true else gui.Visible = false end --Script two local button = script.Parent local gui = script.Parent.Parent.Parent.KartBuyGUI local lit = button.MouseButton1Click local open = script.Parent.Parent.Open if lit then open = true end if open == true then gui.Visible = true end if gui.Visible == true then if not lit then if not open then gui.Visible = false end end end
The code in these if statements are run, regardless of the fact if they're true or not.
You didnt define the value property of your boolean
, so your just comparing a bool to a Instance
. Also if the boolean is only being used by the local script then you could just use a variable defined as a boolean instead. Another thing is that your getting the Open Gui via StarterGui which you really dont need to do, since your LocalScript is in StarterGui.
local open = game.StarterGui.ScreenGui.KartChoiceGUI.Open local gui = script.Parent if open.Value == true then gui.Visible = true else gui.Visible = false end --Script two local button = script.Parent local gui = script.Parent.Parent.Parent.KartBuyGUI local open = game.StarterGui.ScreenGui.KartChoiceGUI.Open button.MouseButton1Click:Connect(function() -- think you want it to execute through a event open.Value = true if open.Value == true then gui.Visible = true end if gui.Visible == true then if not open.Value then gui.Visible = false end end)
and your defining a variable as the MouseButton1Click
event and using it in a If
statement which wont work since it isnt a bool.