Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make a textbox and button appear when i click a box?

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

2 answers

✓ Accepted answer

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.

3 comments

0

i tweaked the script, placed it in the right area, and i turned the default setting for the textbox and button's visibility to false, but now when i clikc the box, it wont make the text box visible

0

Show me what the script looks like , and where you've put it. It should also be a local script.

0

Wow you got an answer accepted but this would only open it? Wow.... So low

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.

2 comments

0

alright, thank you! now how do i get the button to work?

0

With an event listener. Line 1 and 4 of the first code block.

This discussion is preserved as it was. New answers, comments, and votes are closed.