Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you hide and show a GUI text with code?

Asked by 5 years ago

I am trying to show and then hide a text box after display a message, however it is not doing that. Code:

01local text = script.Parent
02game.StarterGui.keytoopendoor.TextLabel.Visible = true
03wait(0.2)
04text.Text = "Y"
05wait(0.1)
06text.Text = "Yo"
07wait(0.1)
08text.Text = "You"
09wait(0.1)
10text.Text = "You n"
11wait(0.1)
12text.Text = "You ne"
13wait(0.1)
14text.Text = "You nee"
15wait(0.1)
View all 44 lines...

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

I'm not exactly sure how you're explorer looks like but here we go.

First, you need to put this into a local script (so only the player can see it), maybe you already have, I'm not sure. Next, instead of game.StarterGui, the gui is already in the player so all we have to do is script.Parent.Parent to reach the gui (which we won't be needing so we just need script.Parent to reach the textlabel if the script is inside of the textlabel). I'm assuming "text" is the textlabel you want to disappear

01local text = script.Parent
02text.Visible = true
03wait(0.2)
04text.Text = "Y"
05wait(0.1)
06text.Text = "Yo"
07wait(0.1)
08text.Text = "You"
09wait(0.1)
10text.Text = "You n"
11wait(0.1)
12text.Text = "You ne"
13wait(0.1)
14text.Text = "You nee"
15wait(0.1)
View all 44 lines...

I tried this in a local script inside a text label and it worked.

0
Thanks for that XxOPGUYxX1234567, actually worked! SwishDash2 5 — 5y
0
No problem! :) XxOPGUYxX1234567 221 — 5y
0
Why were you down voted if this worked? killerbrenden 1537 — 5y
0
And if this is the answer, please mark it as an answer so people know this question has been solved. killerbrenden 1537 — 5y
Ad
Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

This is because you’ve referenced StarterGui. This is a replication container for all GUI instances, it’s purpose it to manage the creation and prior display of the affiliated UI, and transfer it to the Client UI container when connected.

The StarterGui is not responsible for managing the GUIs that are present on the users screen once joined, therefore using it to reference the GUIs within it won’t actually change the authentic GUIs, which were replicated into a container called PlayerGui.

To make affecting changes, you need to reference the PlayerGui instead:

01local Player = game:GetService("Players").LocalPlayer
02local PlayerGui = Player:WaitForChild("PlayerGui")
03 
04local TextLabel = script.Parent
05local KeyToOpenDoorMessage = PlayerGui:WaitForChild("keytoopendoor")
06 
07local TypeWriteString = "You need a key to open this door!"
08 
09KeyToOpenDoorMessage.Visible = (not KeyToOpenDoor.Visible)
10 
11--// This will give you the same effect, without taking up space
12for letter = 1,#TypeWriteString do wait(.1)
13   TextLabel.Text = TypeWriteString:sub(1,letter)
14end
15 
16KeyToOpenDoorMessage.Visible = (not KeyToOpenDoor.Visible)

Answer this question