Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Please Help me Understand Accessing PlayerGui!?

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!

1 comment

0

Might I clarify. First off your answers are all are right, however I need it to update an existing Textline, without dying.

2 answers

✓ Accepted answer

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.

3 comments

0

Might I clarify. First off your answers are all are right, however I need it to update an existing Textline, without dying.

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!

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.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.