I'm trying to have a script what makes the frame disappear when the button is clicked but it doesn't work. It doesn't work
1 | 1 do button.MouseButton 1 Click:connect( function () |
2 | 2 frame.Visible = not frame.Visible |
3 | 3 end |
when I press the button the frame just stay there.
Thanks but it says button and frame are unknown.
Use the code blocks for code, and don't bother doing the line numbers. the code block does it for you.
Answer:
All Gui objects (except the Guis themselves) have a bool property called Visible. So:
1 | button.MouseButton 1 Down:connect( function () |
2 | frame.Visible = false |
3 | end ) -- also, these types of functions have a ')' after the end |
Also, you need to define everything (like the button) that you will use in the script.
Answer : The button and the frame are not defined so
1 | button = script.Parent --Make sure that the script is in the button |
2 | frame = script.Parent.Parent.FrameName --Replace the name of the frame here |
3 | button.MouseButton 1 Click:connect( function () |
4 | frame.Visible = false |
5 | end |
If you would like it to reappear when they click it again, then
1 | button = script.Parent |
2 | frame = script.Parent.Parent.FrameName -- Replace the name of the frame here |
3 | function onClicked() |
4 | if frame.Visible = = true then |
5 | frame.Visible = false |
6 | else |
7 | frame.Visible = true |
8 | end |
9 | button.MouseButton 1 Click:connect(onClicked) |
It's as easy as that
Here:
1 | local b = script.Parent |
2 | local fr = script.Parent.Parent.Frame -- Replace Frame with the Frame's name |
3 | b.MouseButton 1 Down:connect( function () |
4 | fr.Visible = not fr.Visible |
5 | end ) |