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

How to use RemoteEvents/Functions to update a GUI across the server?

Asked by 6 years ago
Edited 6 years ago

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!

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago

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)
0
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? PyccknnXakep 1225 — 6y
0
Yep you don't have to worry about replicating any of that since it's being executed from the server Goulstem 8144 — 6y
0
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? PyccknnXakep 1225 — 6y
0
...And end it when I want it to? PyccknnXakep 1225 — 6y
View all comments (11 more)
0
er... It should start when there are enough players and should end when the round ending prerequisites are met Goulstem 8144 — 6y
0
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. PyccknnXakep 1225 — 6y
0
use the `break` command to exit the loop You can check prerequisites every iteration Goulstem 8144 — 6y
0
No I didn't mean "it should" I meant you should make it like that Goulstem 8144 — 6y
0
`repeat wait() until #game.Players:GetPlayers() > MINIMUMPLAYERAMOUNT` Goulstem 8144 — 6y
0
Ok, when I break the loop how can I start it back up again? PyccknnXakep 1225 — 6y
0
The `break` command is standalone - if used in a loop, it will "break" the loop and therefore the next iteration will never be reached. Goulstem 8144 — 6y
0
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 Goulstem 8144 — 6y
0
Ok, I got it. Thank you for the help> PyccknnXakep 1225 — 6y
0
that's what the while loop is for - to start the loop again Goulstem 8144 — 6y
0
Yup np ;D Goulstem 8144 — 6y
Ad

Answer this question