I'm trying to get my game completed, and what I need to finish it off is how I can update the GUI so all players have the same text. Basically what I'm trying to say is, my script (localscript) has a countdown that relies on the text label to display the countdown. It works, but the problem is the countdown is different for each player, causing different teleportation times and game starting times. Basically I want the countdown in sync with each player whether they join late or not. If that makes sense. I've done some research on how to do this, but none of this makes sense to me. All I need is some sort of example. Any help please? Thank you!
✓ ANSWER ACCEPTED
How to use RemoteEvents/Functions to update a GUI across the server?
1 answer
✓ Accepted answer
FireAllClients is going to be your savior.
Essentially, have your game script and use the FireAllClients function on a RemoteEvent in ReplicatedStorage.
Then, have a LocalScript on the client that recieves it using the OnClientEvent event.
Script:
local re = game.ReplicatedStorage.UpdateUI --This is your RemoteEvent
local timer = 60 --Game duration
while true do
for i = timer,0,-1 do
re:FireAllClients(i);
wait(1);
end
end
LocalScript:
local re = game.ReplicatedStorage.UpdateUI --This is your RemoteEvent
local label = script.Parent --TextLabel or whatever to display on
re.OnClientEvent:Connect(function(text) --'text' is what was passed
label.Text = text;
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

15 comments
My script in the GUI is set to loop this so it countdowns, kills players, uses CFrame to open a door, teleports players, closes the door, tweens a frame, rinse and repeat. Would the rest of my script work for all clients aswell?
Yep you don't have to worry about replicating any of that since it's being executed from the server
Ok but when the countdown stops, it keeps looping. How could I make it so I can start the countdown when I want it to?
...And end it when I want it to?
er... It should start when there are enough players and should end when the round ending prerequisites are met
It's not. When the countdown ends, it starts the countdown again. This is probably because of while true do. I got rid of while true do and it doesnt repeat, but I want the countdown to start back up again after Intermission is over.
use the
breakcommand to exit the loop You can check prerequisites every iterationNo I didn't mean "it should" I meant you should make it like that
repeat wait() until #game.Players:GetPlayers() > MINIMUMPLAYERAMOUNTOk, when I break the loop how can I start it back up again?
The
breakcommand is standalone - if used in a loop, it will "break" the loop and therefore the next iteration will never be reached.for i = 1,10 do if i > 5 then break end print(i) end --> would print up to 5 cause we used the break command after that
Ok, I got it. Thank you for the help>
that's what the while loop is for - to start the loop again
Yup np ;D