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.
1 comment
My output is nothing's happening.