My text isn't changing after 20 seconds

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.

3 Likes
  1. I have really much script (Like this script is %20 of the minigame) if you want, i can show it for understant the problem.

  2. In other scripts, i setup new players can’t reach to minigames. So, that’s not problem for me.

Note: This script is in ServerScriptService.

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.

1 Like

Why arent you using a
for i = 20, 0 , -1 do loop for the countdown?

I thought it was an advice… Thank you for the solution.

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.