generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

How do I make a TextButton open a TextLabel?

Previous Thread :: Next Thread 
Sectanza is not online. Sectanza
Joined: 18 Feb 2016
Total Posts: 27
22 Apr 2016 11:55 AM
Pretty stupid and basic question, I know, but can I get a script that makes a TextButton open a TextLabel when clicked on and close the TextLabel when clicked again? All my GUIs are in StarterGui. Thank you in advance.
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
22 Apr 2016 12:06 PM
TextButton.MouseButton1Click:connect(function()
if not TextLabel.Visible then
TextLabel.Visible = true
else
TextLabel.Visible = false
end
end)

This is pretty basic, no animations etc.
Don't forget that TextButton and TextLabel are not actual objects, you need to identify them.

(like:

local TextLabel = script.Parent.TextLabel

)


no siggy for you
Report Abuse
Selerity is online. Selerity
Joined: 20 Jan 2013
Total Posts: 204
22 Apr 2016 12:13 PM
A function must be used. You need to use a MouseButton1Down event which is basically an event that starts a function when a certain thing is clicked. In your case, that certain thing is the text button. Also make sure the script is Local and not a standard one because you only want the button to open when it's clicked by an individual.
-----------------------------------------------
LAYOUT:

local label = game.StarterGui.TextLabel
local button = game.StarterGui.TextButton

function FUNCTIONNAME()
if label.Visible == false then
label.Visible = true
else label.Visible = false
end
end


button.MouseButton1Down:connect(FUNCTIONNAME)
-----------------------------------------------

I'm not actually on studio rn, so tell me if it works or not.


Report Abuse
Sectanza is not online. Sectanza
Joined: 18 Feb 2016
Total Posts: 27
22 Apr 2016 12:29 PM
Either I'm doing something wrong or it's not working. I put it in a Local Script inside the text button with the text label (StarterGui -> ScreenGUI - > TextButton -> LocalScript, TextLabel). Do I need to move things around, or is there something in the script I need to be changing? I'm dumb--a noob, per say--when it comes to scripting, sorry. ^^'
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
22 Apr 2016 12:30 PM
local TextLabel = script.Parent:WaitForChild("TextLabel")
local TextButton = script.Parent

TextButton.MouseButton1Click:connect(function()
if not TextLabel.Visible then
TextLabel.Visible = true
else
TextLabel.Visible = false
end
end)



no siggy for you
Report Abuse
Selerity is online. Selerity
Joined: 20 Jan 2013
Total Posts: 204
22 Apr 2016 12:33 PM
Just do what the other guy said. I'm a noob too lmao, you're not alone. Just recently started scripting. Felt like helping, but I guess I failed. :(


Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
22 Apr 2016 12:34 PM
^^^ Everything was perfectly correct though :)

'

local label = game.StarterGui.TextLabel
local button = game.StarterGui.TextButton

'

This part is just incorrect. First off you can only access a player's gui by doing the following:

game.Players.PlayerName.PlayerGui

But if the script is in the player already, then you can just use script.Parent to access those objects.


no siggy for you
Report Abuse
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
22 Apr 2016 12:36 PM
Screenshot of explorer in studio would make this easier
Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
22 Apr 2016 12:37 PM
^(StarterGui -> ScreenGUI - > TextButton -> LocalScript, TextLabel)

Maybe reading would too..
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
22 Apr 2016 12:38 PM
@Darth

prntscr.com/avj3dj


no siggy for you
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
22 Apr 2016 12:39 PM
If you were wondering, WaitForChild should be used in LocalScripts cause they usually run earlier than the TextLabel has actually loaded, and it won't see the TextLabel, thus returning an error.


no siggy for you
Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
22 Apr 2016 12:43 PM
TextLabel=script.Parent.TextLabel
TextButton=script.Parent

TextButton.MouseButton1Click:connect(function(player)
player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild:("TextButton"):WaitForChild("TextLabel")

if not TextLabel.Visible then
TextLabel.Visible = true
else
TextLabel.Visible = false
end
end)

This is windows's script, I just fixed the pathing and added WaitForChild
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
22 Apr 2016 12:44 PM
^if the script were to be in the textbutton as she said, that's just going the hard way


no siggy for you
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
22 Apr 2016 12:44 PM
"Either I'm doing something wrong or it's not working. I put it in a Local Script inside the text button with the text label (StarterGui -> ScreenGUI - > TextButton -> LocalScript, TextLabel). Do I need to move things around, or is there something in the script I need to be changing? I'm dumb--a noob, per say--when it comes to scripting, sorry. ^^'"

"(StarterGui -> ScreenGUI - > TextButton -> LocalScript, TextLabel)"


no siggy for you
Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
22 Apr 2016 12:46 PM
How is that hard?
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
22 Apr 2016 12:47 PM
why would you use
player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild:("TextButton"):WaitForChild("TextLabel")

if you can use script.Parent instead

it's way shorter


no siggy for you
Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
22 Apr 2016 12:48 PM
Eh, if it works it works, I like to do multiple checks just to make sure.
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
22 Apr 2016 12:49 PM
okay
as long as it works


no siggy for you
Report Abuse
Sectanza is not online. Sectanza
Joined: 18 Feb 2016
Total Posts: 27
22 Apr 2016 01:24 PM
@iWindowz
Your second script works! Thank you for the help :D
Report Abuse
XboxVodoo is not online. XboxVodoo
Joined: 06 Aug 2015
Total Posts: 6
22 Apr 2016 01:27 PM
U G@VE M3 ALL UR R$ & SOM UF D@T B@@TY


BOB
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image