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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 22 Apr 2016 12:36 PM |
| Screenshot of explorer in studio would make this easier |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 05 Jan 2013 |
| Total Posts: 1809 |
|
|
| 22 Apr 2016 12:38 PM |
@Darth
prntscr.com/avj3dj
no siggy for you |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 22 Apr 2016 01:27 PM |
U G@VE M3 ALL UR R$ & SOM UF D@T B@@TY
BOB |
|
|
| Report Abuse |
|
|