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

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

Asked by
elian11 10
8 years ago
Edited 8 years ago

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.

01--This is an attempt of me doing it.
02local p = "elian11";
03 
04local t = game.Players:GetChildren();
05local timer = t.PlayerGui.Timer.Frame.TextLabel
06 
07game.Players.ChildAdded:connect(function (newPlayer)
08if (newPlayer.Name ~= p) then return; end
09newPlayer.Chatted:connect(function (msg)
10msg = msg:lower();
11if (msg == "raid/timerstart") then
12timer.Text = "This script works"
13--You can ignore this part, I will add it once it starts working.
14 
15end
16end);
17end);

2 answers

Log in to vote
0
Answered by
MHaven1 159
8 years ago

http://wiki.roblox.com/index.php?title=API:Class/Instance/GetChildren

you are missing for i,v in pairs () do

use the link above to fix your script.

Ad
Log in to vote
0
Answered by 8 years ago

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:

01local p = "elian11";
02 
03local t = game.Players:GetChildren();
04local timer = t.PlayerGui.Timer.Frame.TextLabel
05 
06game.Players.ChildAdded:connect(function (newPlayer)
07if (newPlayer.Name ~= p) then return; end
08newPlayer.Chatted:connect(function (msg)
09msg = msg:lower();
10if (msg == "raid/timerstart") then
11for i,v in pairs(t) do
12v.PlayerGui.Timer.Frame.TextLabel.Text = "This script works."
13end
14end
15end);
16end);

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.

Answer this question