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

Why wont this GUI become visible when TextLabel.Text == ¨something¨ ?

Asked by 4 years ago

So I have a TextLabel that changes the text every few seconds and I am trying to make a Frame that becomes visible when the text in TextLabel says a certain thing. Script for the Frame:

if game.StarterGui.ScreenGui.TextLabel.Text == ¨Text¨ then
    script.Parent.Visible = true -- Frame
end

Anyone know where I went wrong here?

3 answers

Log in to vote
0
Answered by 4 years ago

You're using StarterGui. If you want things to update immediately, use PlayerGui.

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

if playergui.ScreenGui.TextLabel.Text == "Text" then
    script.Parent.Visible = true
end
Ad
Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
4 years ago

Its likely because you are trying to use StarterGui instead of PlayerGui. I don't believe code is executed in StarterGui and it wouldn't align with the client anyway.

Do this instead.

if game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text == ¨Text¨ then
    script.Parent.Visible = true -- Frame
end
Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

I think it's because on line 3 you didn't reference the object that is being called the changing line 3 with also playergui is more efficient than startergui also playergui is for clients whereas startergui is for GUIs Another reason why this won't work is because things such as text requires data like tostring and tonumber

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

if playergui.ScreenGui.TextLabel.Text == "Text" then
    script.Parent.Frame.Visible = not script.Parent.Frame.Visible
end

Answer this question