What im trying to do is i have a box and when i click it i want a text box and button to appear, and when i click the button it goes away. the problem is that when i click the box it wont become visible! my script:
pine = workspace.pine repeat if pine.ClickDetector.MouseButton1Click:connect(function(b) then game.StarterGui.ScreenGui.TextBox.Visible = true game.StarterGui.ScreenGui.TextButton.Visible = true end
You've combined an if statement with a function. Although this doesn't fix it, I'll show you what you did wrong. Change this line:
if pine.ClickDetector.MouseButton1Click:connect(function(b) then
To this:
pine.ClickDetector.MouseButton1Click:connect(function(b)
And at line 6, change:
end
To:
end)
Also, the whole thing wouldn't work anyway. You need to put this script into the StarterGui and redo it because I'm assuming you only want this to happen to the player who clicked the box, not to everyone in the game.
Theres a simple method of turning 5 lines into one for this kind of thing. also the repeat and if statement are useless in this. You are declaring an event listener. This will fire whenever it happens, no need to constantly check for it.
pine.ClickDetector.MouseButton1Click:connect(function(p) -- declare the listener game.StarterGui.ScreenGui.TextBox.Visible = not game.StarterGui.ScreenGui.TextBox.Visible -- not statement will reverse the current visible. if true, false. if false, true. game.StarterGui.ScreenGui.TextButton.Visible = not game.StarterGui.ScreenGui.TextButton.Visible -- same thing for other gui object. end)
EDIT: found the other answer is just as useless... game.StarterGui.ScreenGui changes the StarterGui. Not what the players see. For this to update, the player needs to be killed or respawned. You must go into the players version of the gui with something like
game.Players[p.Name].PlayerGui.ScreenGui.Textbox.Visible = not game.Players[p.Name].PlayerGui.ScreenGui.Textbox.Visible -- just so the player sees the change.
HOWEVER: Local scripts should be used for this kind of thing.