Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why is this button not working?

Asked by 9 years ago

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!

1 answer

Log in to vote
1
Answered by 9 years ago
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.

0
this will open the GUI, but not close it. mariowikiguy 20 — 9y
0
I edited it, try the new one. It should work. mrgeorge12345 45 — 9y
0
Thanks! It works now. mariowikiguy 20 — 9y
Ad

Answer this question