I am trying to make it so that when you click the button it will change the textButtons name and make the visibility of a frame true. NOTE: The textbutton and frame are in different ScreenGui's if that is the problem. The output of the script below is: attempt to index global 'we' (a nil value)
basic = game.StarterGui.BasicMath button = game.StarterGui.Buttons.Frame.BasicMath button.MouseButton1Down:connect(function() if button.Text == "Basic Math" then basic.Frame.Visible = true button.Text = "Close" elseif button.Text == "Close" then basic.Frame.Visible = false button.Text = "BasicMath" end end)
The error that you've cited in your original post isn't present in the script segment that you've posted, though there are two issues that you'll run into with that segment despite this.
As it currently stands, you wouldn't see a change. This is because you're editing the GUI that's in StarterGui, rather than the GUI that's in the player's PlayerGui. This means that in order for a player to see the change they would currently need to reset.
You also had a second error. When the user was "closing" the GUI the button's text was changed to "BasicMath". This meant that the GUI could never be "opened" again as the if statement is checking whether the button's text is equal to "Basic Math", not "BasicMath".
Note: Both of the below assume you're doing this from a LocalScript.
local Player = game.Players.LocalPlayer local BasicMath = Player.PlayerGui.BasicMath local Button = Player.PlayerGui.Buttons.Frame.BasicMath Button.MouseButton1Down:connect(function() if Button.Text == "Basic Math" then BasicMath.Frame.Visible = true Button.Text = "Close" else BasicMath.Frame.Visible = false Button.Text = "Basic Math" end end)
Though, you could also condense your script a bit by using a ternary operator and a not operator (to "toggle" visibility).
local Player = game.Players.LocalPlayer local BasicMath = Player.PlayerGui.BasicMath local Button = Player.PlayerGui.Buttons.Frame.BasicMath Button.MouseButton1Down:connect(function() Button.Text = Button.Text == "Basic Math" and "Close" or "Basic Math" BasicMath.Frame.Visible = not BasicMath.Frame.Visible end)