I'm making a GUI Intro for all my games. I've created the GUI, and I've done this:
print("Close button loaded") button = script.Parent window = script.Parent.Parent.Parent.Parent function onClicked(GUI) window:remove() end script.Parent.MouseButton1Click:connect(onClicked)
But it isn't working. Help me please!
My GUI is -StarterGUI -IntroGUI -Frame,Textbox -TextBox -Script
local Button = script.Parent -- TextButton local Window = script.Parent.Parent.Parent.Parent -- ScreenGui or Frame, whatever is being removed. Button.MouseButton1Click:connect(function() Window:Destroy() end)
Remember to use a TextButton and make sure you have the directory correct. The use of an anonymous function allows you to do this much more efficiently with less typing work.
Try using the line window.Visible = false
instead of removing it.
Also, what output are you getting?
So,
print("Close button loaded") button = script.Parent window = script.Parent.Parent.Parent.Parent function onClicked(GUI) window.Visible = false end script.Parent.MouseButton1Click:connect(onClicked)
I'll try it. And the output is nothing happens.
Okay, I just tried it. Nothing Happen.
print("Close button loaded") button = script.Parent window = script.Parent.Parent.Parent.Parent function onClicked() window:Destroy() end script.Parent.MouseButton1Down:connect(onClicked)
Try that one, It might work.
It is because you have a TextBox. Use a TextButton instead.
I've encountered this problem many times and have tried and tried to fix it. Eventually I fixed it. You have to put the code into a local script and insert it into the GUI making it's parent the GUI, NOT the button. So it looks like this: StarterGUI - YourGUI - LocalScript . And as for the code:
local button = script.Parent.[FrameNameGoesHere] local window = script.Parent.[FrameNameGoesHere] local variable = script.Parent.[FrameNameGoesHere] function onClicked(GUI) window:Destroy() end button.MouseButton1Click:connect(onClicked)
Note that I have removed print("Close button loaded")
, you don't need that. It's sort of a line of unnecessary code users put into their scripts as some way of assuring it works. Well it makes no difference at all! It won't make your script run any differently, so I suggest you leave it out.
Note also that the local
tags are added because they only apply to a certain player, not everyone in the game. You will not need to use the local tags later in the code when calling the variables.
Note finally that I have changed script.Parent.MouseButton1Click:connect(onClicked)
to button.MouseButton1Click:connect(onClicked)
, this is because we changed the location of the script meaning script.Parent
is no longer valid and will throw errors when tested. We can also use our variable 'button' in that line as it is the same as script.Parent
but with the correct layout.
This worked for me, and should work for you.
And also, if you are using a TextBox please change it to a TextButton as a TextBox is for typing/entering and a TextButton is for clicking.
u cant make a Gui invisible... u can only do it to its children like Fram or a Button etc...