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

How do I enable a Gui from a normal script? [Solved]

Asked by
Mayk728 855 Moderation Voter
7 years ago
Edited 7 years ago

This is probably the most confusing thing in the world for me, and i can never seem to figure it out. Let me just start simple here. I have a script in Workspace and I want it to make a TextLabel inside a ScreenGui visible. I have no clue how to access it from there.

TextLabel = game.Players.Name.PlayerGui.Regen.TextLabel
TextLabel.Visible = false
wait(3)
TextLabel.Visible = true

I also tried "game.Players.PlayerName.Regen.TextLabel" but still not helping. Anyone know how to do that?

1 answer

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

I assume that you want to turn player's TextLabel invisible. Your problem is that you didn't include Player. By doing:

game.Players.Name.PlayerGui.Regen.TextLabel

You are "telling" the script to find player with name "Name" which doesn't have to exist.

to get player from ServerScript you may use PlayerAdded event

game.Players.PlayerAdded:connect(function(player) -- Player Variable

end)

Now that we have Player variable we can access to the Player's PlayerGui.

The final script:

game.Players.PlayerAdded:connect(function(player) -- Player Variable
local TextLabel = player.PlayerGui.Regen.TextLabel
TextLabel.Visible = false
wait(3)
TextLabel.Visile = true
end)

Note that this will happen when player joins the game.

To do this whenever you want just use LocalScript.

For Player variable type this:

local Player = game.Players.LocalPlayer -- This can be used only in LocalScripts
0
*local TextLabel* thanks ;p RubenKan 3615 — 7y
0
Thank you! This worked for me. By the way, it showed Regen wasn't a valid member of PlayerGui so i did "player.PlayerGui:WaitForChild("Regen"):FindFIrstChild("TextLabel")" Mayk728 855 — 7y
0
so, this "enables" a gui how? connor12260311 383 — 7y
0
He just has a small typo "TextLabel.Visile" should be "TextLabel.Visible" I'm pretty sure that should fix it. songboy50 77 — 5y
Ad

Answer this question