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 4 years ago

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

local text = script.Parent
game.StarterGui.keytoopendoor.TextLabel.Visible = true
wait(0.2)
text.Text = "Y"
wait(0.1)
text.Text = "Yo"
wait(0.1)
text.Text = "You"
wait(0.1)
text.Text = "You n"
wait(0.1)
text.Text = "You ne"
wait(0.1)
text.Text = "You nee"
wait(0.1)
text.Text = "You need"
wait(0.1)
text.Text = "You need a"
wait(0.1)
text.Text = "You need a k"
wait(0.1)
text.Text = "You need key"
wait(0.1)
text.Text = "You need key t"
wait(0.1)
text.Text = "You need key to"
wait(0.1)
text.Text = "You need key to o"
wait(0.1)
text.Text = "You need key to op"
wait(0.1)
text.Text = "You need key to ope"
wait(0.1)
text.Text = "You need key to open"
wait(0.1)
text.Text = "You need key to open t"
wait(0.1)
text.Text = "You need key to open th"
wait(0.1)
text.Text = "You need key to open thi"
wait(0.1)
text.Text = "You need key to open this"
wait(3)
game.StarterGui.keytoopendoor.TextLabel.Visible = false



















2 answers

Log in to vote
2
Answered by 4 years ago
Edited 4 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

local text = script.Parent
text.Visible = true
wait(0.2)
text.Text = "Y"
wait(0.1)
text.Text = "Yo"
wait(0.1)
text.Text = "You"
wait(0.1)
text.Text = "You n"
wait(0.1)
text.Text = "You ne"
wait(0.1)
text.Text = "You nee"
wait(0.1)
text.Text = "You need"
wait(0.1)
text.Text = "You need a"
wait(0.1)
text.Text = "You need a k"
wait(0.1)
text.Text = "You need key"
wait(0.1)
text.Text = "You need key t"
wait(0.1)
text.Text = "You need key to"
wait(0.1)
text.Text = "You need key to o"
wait(0.1)
text.Text = "You need key to op"
wait(0.1)
text.Text = "You need key to ope"
wait(0.1)
text.Text = "You need key to open"
wait(0.1)
text.Text = "You need key to open t"
wait(0.1)
text.Text = "You need key to open th"
wait(0.1)
text.Text = "You need key to open thi"
wait(0.1)
text.Text = "You need key to open this"
wait(3)
text.Visible = false

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

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

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local TextLabel = script.Parent
local KeyToOpenDoorMessage = PlayerGui:WaitForChild("keytoopendoor")

local TypeWriteString = "You need a key to open this door!"

KeyToOpenDoorMessage.Visible = (not KeyToOpenDoor.Visible)

--// This will give you the same effect, without taking up space
for letter = 1,#TypeWriteString do wait(.1)
   TextLabel.Text = TypeWriteString:sub(1,letter)
end

KeyToOpenDoorMessage.Visible = (not KeyToOpenDoor.Visible)

Answer this question