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

GUI closing Script?

Asked by 10 years ago

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

7 answers

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

Ad
Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

Try using the line window.Visible = false instead of removing it.

Also, what output are you getting?

0
My output is nothing's happening. VirtualFlying 55 — 10y
Log in to vote
0
Answered by 10 years ago

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.

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

Log in to vote
0
Answered by 10 years ago

It is because you have a TextBox. Use a TextButton instead.

0
I have done that. Still nothing has happened. VirtualFlying 55 — 10y
Log in to vote
0
Answered by
Nytroz 15
10 years ago

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.Parentis 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.Parentbut 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.

0
Try running your game in Solo with the Output Window. There will be no errors when you click and the GUI will close normally. Nytroz 15 — 10y
0
Apperently the first line isn't correct, as it is underlined in red. VirtualFlying 55 — 10y
0
Have you changed what was in my code to suit yours? Otherwise, of course it will be red Nytroz 15 — 10y
Log in to vote
-1
Answered by
KAAK82 16
10 years ago

u cant make a Gui invisible... u can only do it to its children like Fram or a Button etc...

Answer this question