Ive tried lots of things but it wont show a gui. theres nothing in the output so why wont it show?
1 | local button = game.StarterGui.ScreenGui.Help |
2 |
3 | button.MouseButton 1 Click:connect( function () |
4 |
5 | game.StarterGui.Info.Information.Active = true |
6 |
7 | end ) |
1 | local function clicked() |
2 |
3 | game.StarterGui.Info.TextBox.Visible = true |
4 | wait( 10 ) |
5 | game.StarterGui.Info.TextBox.Visible = false |
6 |
7 | game.StarterGui.ScreenGui.TextButton.MouseButton 1 Click:connect(clicked) |
8 | end |
First of all, you really don't want to adjust the GUIs in the StarterGui, because that is a service that gives a copy of the GUI to the players' PlayerGui, therefore the change won't be visible right away.
What the code should be accessing is the players' PlayerGui, because that's where the players' real-time displayed GUIs are stored.
1 | -- Since I'm using LocalPlayer, this MUST be in a LocalScript. |
2 | -- Since this is supposed to be in a LocalScript, a :WaitForChild() method is recommended to utilize. |
3 |
4 | local GUI = game.Players.LocalPlayer.PlayerGui:WaitForChild( "ScreenGui" ) |
5 | local button = GUI:WaitForChild( "Help" ) |
6 | button.MouseButton 1 Click:connect( function () |
7 | game.Players.LocalPlayer.PlayerGui.Info.Information.Active = true |
8 | end ) |
1 | -- For this function, put your connection line OUTSIDE; otherwise the function won't fire if the connection line is within an 'unfired' function. |
2 |
3 | local function clicked() |
4 | game.Players.LocalPlayer.PlayerGui.Info.TextBox.Visible = true |
5 | wait( 10 ) |
6 | game.Players.LocalPlayer.PlayerGui.Info.TextBox.Visible = false |
7 | end |
8 | game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.MouseButton 1 Click:connect(clicked) |
If your script is within one of the GUIs, then I recommend referring your GUI objects starting from the script (such as script.Parent
).
EXAMPLE
Let's assume your script is within ScreenGui
. You don't necessarily have to have a LocalScript this way. You could use script.Parent.Parent.Info
to access the Info
GUI.
1 | local GUI = script.Parent |
2 | local button = GUI:WaitForChild( "Help" ) |
3 | local InfoGui = GUI.Parent:WaitForChild( "Info" ) |
4 | button.MouseButton 1 Click:connect( function () |
5 | InfoGui.Information.Active = true |
6 | end ) |
01 | local GUI = script.Parent |
02 | local TB = GUI:WaitForChild( "TextButton" ) |
03 | local InfoGui = GUI.Parent:WaitForChild( "Info" ) |
04 |
05 | local function clicked() |
06 | InfoGui.TextBox.Visible = true |
07 | wait( 10 ) |
08 | InfoGui.TextBox.Visible = false |
09 | end |
10 |
11 | TB.MouseButton 1 Click:connect(clicked) |
12 | -- NOTE: You don't have to have a plethora of variables with a :WaitForChild() method, especially if the script is server-sided. |
13 | --But it's a habit for me because I'm quite meticulous when it comes to scripting, as I want to avoid as much errors as possible. |
1 | script.Parent.MouseButton 1 Click:connect( function () |
2 |
3 | game.StarterGui.TextButton.Visible = true |
4 |
5 | end ) |
1 | script.Parent.MouseButton 1 Click:connect( function () |
2 |
3 | script.Parent.Parent.VISIBLEME.Visible = true |
4 |
5 | end ) |
You need to tell it where you want it to click
Put the script inside the button you want to become visible
EDIT: Make a button and make the button name that you want to be visible be called VISIBLEME
If it does then go to the wiki and learn more basics.