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

How do I change the GUI for everyone in a server if it's in StarterGUI?

I'm trying to add a timer script where when I type a message, a timer starts ticking down on everyone's GUI. The trouble I am having is accessing everyone's GUI's at the same time to change them all at the same time. The script is currently in ServerScriptService and the GUI itself is in StarterGUI. I guess you could say that this kind of GUI is like a server-wide message that I control when it starts.

--This is an attempt of me doing it.
local p = "elian11";

local t = game.Players:GetChildren();
local timer = t.PlayerGui.Timer.Frame.TextLabel

game.Players.ChildAdded:connect(function (newPlayer)
if (newPlayer.Name ~= p) then return; end
newPlayer.Chatted:connect(function (msg)
msg = msg:lower();
if (msg == "raid/timerstart") then
timer.Text = "This script works"
--You can ignore this part, I will add it once it starts working.

end
end);
end);

2 answers

Hi! I see your problem, and the best solution to your problem is to use an in pairs loop. Basically, I have fixed up your script and this is the fixed version:

local p = "elian11";

local t = game.Players:GetChildren();
local timer = t.PlayerGui.Timer.Frame.TextLabel

game.Players.ChildAdded:connect(function (newPlayer)
if (newPlayer.Name ~= p) then return; end
newPlayer.Chatted:connect(function (msg)
msg = msg:lower();
if (msg == "raid/timerstart") then
for i,v in pairs(t) do
v.PlayerGui.Timer.Frame.TextLabel.Text = "This script works."
end
end
end);
end);

What I did was I used an in pairs loop to loop through all the players, and if the player has the gui then it will change the timer's textlabel' for every player.

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