I am trying to get a button (script.Parent) to make a GUI appear or disappear when you click on it. Why is it not working?
local button = script.Parent local gui = game.Lighting.ScreenGui function onClick(p) if (gui.Parent == p.PlayerGui) then gui.Parent = game.Lighting end if (gui.Parent == game.Lighting) then gui.Parent = p.PlayerGui end end button.MouseButton1Click(onClick)
Thanks!
local button = script.Parent local gui = game.Lighting.ScreenGui function onClick() --You didn't need the p if gui.Parent == script.Parent.Parent.Parent then -- basically: script->button->gui->playergui gui.Parent = game.Lighting else gui.Parent = script.Parent.Parent.Parent end end button.MouseButton1Down:connect(onClick) --You needed the :connect to connect your function --Also, don't use MouseButton1Click, use MouseButton1Down
This should work, sorry if it doesn't, my studio kept crashing and I couldn't test it.
Edit: I added an "else" to the if-then statement, so if the parent isn't PlayerGui, it'll change the gui's parent to PlayerGui.