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

Please Help me Understand Accessing PlayerGui!?

Asked by 8 years ago

Hey guys! I'm currently trying to make a game (like most of you) and I've ran into a problem... See in the past (3 years or so ago), I remember all you had to do to update your TextLabel or button etc. was to do something like this:

script.Parent.StarterGui.ScreenGui.Frame.TextLabel.Text = "WORK"

But now with a few updates they have seemed to change that and now you have to access the PlayerGui, and frankly I do not know how to do that, nor have I found a clear explanation on accessing it.

This is my attempt:

script.Parent.Parent.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.TextLabel.Text = "Game is Starting in 30"

and it spits out "Players is not a valid member of Player" in ROBLOX Studio, but to my understanding Player is a part of Players.

Anyways I'd love it if someone explained to me how to access PlayerGui so I could progress my game, and possibly help other people who don't quite understand it as well.

Thanks!

Status: Solved!

0
Might I clarify. First off your answers are all are right, however I need it to update an existing Textline, without dying. Firebeats121ALT 5 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

It's rather simple to access it.

I'm not exactly sure what you're trying to get at with your script, but here's how I access it for one player:

game.Players.SouthCaroIina.PlayerGui.ScreenGui.Frame.TextLabel.Text = "Game is Starting in 30"

If you're accessing multiple players then you would use pairs, like this:

for i, v in pairs(game.Players:GetChildren()) do --[[Here is where you would add if, then statements to only access certain players, as you probably know. But if you're accessing all of them, that is unnecessary.]]
v.PlayerGui.ScreenGui.Frame.TextLabel.Text = "Game is Starting in 30"

I'm going to assume that script.Parent.Parent is Workspace.

If you're literally trying to use LocalPlayer as to index the play using the script, I haven't ever done anything involving that before. I'd need further information to help anymore than this.

0
Might I clarify. First off your answers are all are right, however I need it to update an existing Textline, without dying. Firebeats121ALT 5 — 8y
0
AHHH, Ignore that last post, I have been putting it in a local script inside the StarterGui, which was somehow screwing up the results (I could of potentially solved it in the past now knowing this) Thanks for the help! Firebeats121ALT 5 — 8y
0
Two problems, Getting the local player is easier than getting the name of the player than indexing, Second, You can use :GetPlayers() instead of :GetChildren() It's safer. NotSoNorm 777 — 8y
Ad
Log in to vote
1
Answered by
NotSoNorm 777 Moderation Voter
8 years ago

Well there are two methods I'm going to tell you, one server and one local.

The first (local script) is simply just using LocalPlayer:

game.Players.LocalPlayer.PlayerGui.Frame.TextLabel.Text = "it works lol"

now the second (server script) is using player added

game.Players.PlayerAdded:connect(function(player)
    player.PlayerGui.Frame.TextLabel.Text = "it works also"
end)

Answer this question