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

Please help me, my local script doesn’t work? and I tried many times working on it.

I don’t know how to make an open and close gui button and I have my Frame ready in.

Here, my script doesn’t work:

local Btn = script.Parent
local frame = script.Parent.Parent.Frame

Btn.MouseButton1Click:Connect(function()
    frame.Visible = true
else
    frame.Visible = false
end)

1 answer

✓ Accepted answer

You're lacking an if statement which is necessary for the 'else' to work, but for this operation no if statement is needed anyway:

local Btn = script.Parent
local frame = script.Parent.Parent.Frame

Btn.MouseButton1Click:Connect(function()
	frame.Visible = not frame.Visible
end)

This just inverts the value of frame.Visible (true -> false and false -> true).

Disclaimer: Activated is preffered over MouseButton1Click because it works on all devices, however the behavior is slightly different. Check the comments for more info.

4 comments

0

Thank you so much! Appreciate that!

0

Hi! This is a good answer, however, usually GuiButton.Activated is better than GuiButton.MouseButton1Click. Would you mind including that in your answer? Thanks

0

Ok sure

0

@TTChaos Hi, the behavior of Activated and MouseButton1Click is different not only because MouseButton1Click doesn't work on some devices, but also because MouseButton1Click requires the mouse button to be released on the GUI button. I'm not sure if the asker intends on implementing that behavior, but I will add it as a disclaimer.

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