Hello developers. Im working on a small minigame project. I created a system that runs random minigame every 20 seconds. The weird thing is my GUI text isn’t changing after “wait(20)” line.
Here is my code.
local class = require(game.ReplicatedStorage.MainFunctions)
local ssto = game:GetService("ServerStorage")
class.Startup()
while true do
local allevents = game.ServerStorage.Events:GetChildren()
local randomevent = allevents[math.random(#allevents)]
local starteventfunc = require(randomevent:FindFirstChild("EventFunction"))
local wrt = game.StarterGui.Nofievent.Frame.TextLabel
wrt.Text = "Next game starts in 20 seconds."
wait(20)
wrt.Text = "Gamemode: "..(randomevent:FindFirstChild("name").Value)
starteventfunc()
wait(30)
game.Lighting:ClearAllChildren()
local skys = ssto.SkyPack:GetChildren()
local randomsky = skys[math.random(#skys)]
local clonesky = randomsky:Clone()
clonesky.Parent = game.Lighting
end
I assume this is the only script in the play and that the text isn’t defaulted to exactly “Next game starts in 20 seconds.”?
I noticed that you are referring to a GUI that not everyone has and new players will see changed UI. That’s because the GUI variable is referring to the one in StarterGui and not each client’s PlayerGui. They are different. Because updating StarterGui rather than PlayerGui, only players who join get this GUI replicated differently depending on what state it is in.
I already pointed out the reason of this behavior. The script isn’t interacting with any player’s GUI at all and only interact with the “stored” copy inside StarterGui which always copy itself over to the player’s PlayerGui.
In order to update this GUI, you will need to fire from server to all clients to update their GUIs with their own LocalScript that listens to a RemoteEvent. Alternatively, you can use a ValueObject(StringObject) instances and change them from server and allow client to observe changes on them.
The matter is not exactly about any countdowns. It’s specifically why the GUI would not update. For this question, it’s a design matter that can be left alone without any problems.