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

How to change text on GUI for EVERY player, DIRECTLY?

Hello, in my game, I have a very complicated and probably way too long script that changes the text of all the players' GUIs'. It basically involves this:

(This is a Script inside the Game)
--> Game wait x amount of seconds
--> Game changes the value of the variable "g_Var" to 1
(This is a LocalScript inside the PlayerGui)
--> LocalScript that's been looping an if/then statement is now active and finally changes the text of the Gui.
--> Game changes value of the variable "g_Var" back to 0 and restarts

I was wondering if there is any simple way to change the text on a GUI, for every player, DIRECTLY through a normal server Script.

2 comments

0

Need a Remote Event.

3 answers

You could do:

for i,v in pairs(game.Players:GetChildren()) do
	v.PlayerGui.ScreenGui.Frame.TextLabel.Text = "Hello World"
end

It is actually pretty simple, the Player's Gui is stored in "game.Players.[PLAYERNAME].PlayerGui". With this information, we can easily get the children of "game.Players" and loop through each player to change what we need.

Here is an example:

local players = game.Players:GetChildren()

for i = 1, #players do
	players[i].PlayerGui.ScreenGui.Frame.TextLabel.Text = "Hello World"
end

Note: This will not work as is if ran right at the start of a server, as no Players are connected yet.

1 comment

0

Server scripts can NOT access the PlayerGui with filtering enabled. This is a poor method.

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