Why doesn't this while true do loop run?

This while true do loop worked fine ~10 mins ago, but after altering some aspects of the code it no longer works. How come?

local Start = 0
local Time = 10
local RoundLabel = game.StarterGui.ScreenGui.RoundLabel
local Blackout = game.StarterGui.BlackoutGui.Frame

while true do
	RoundLabel.Text = "The Round Starts in: "..Time.." Seconds!"
	wait(1)
	Time = Time - 1

	if Time == Start then

		break
	end
end

RoundLabel.Text = "Starting the Round!"

wait(2)
Blackout.Visible = true

You assigned the parameters incorrectly. It must be:

local player = game.Players.LocalPlayer
local RoundLabel = player.PlayerGui.ScreenGui.RoundLabel
local Blackout = player.PlayerGui.BlackoutGui.Frame

StarterGui is different between PlayerGui.

local Start = 0
local Time = 10
local RoundLabel = game.StarterGui.ScreenGui.RoundLabel
local Blackout = game.StarterGui.BlackoutGui.Frame

while task.wait() do
	RoundLabel.Text = "The Round Starts in: "..Time.." Seconds!"
	wait(1)
	Time = Time - 1
	if Time == Start then
		break
	end
end

RoundLabel.Text = "Starting the Round!"
wait(2)
Blackout.Visible = true

Local script, place it in StarterGui.

1 Like

Little typo there, there shouldn’t be a period after that

1 Like

This won’t work, see @ZacharyZaxorDDD’s solution, your code has the same problem as OP. OP’s main code body works, it’s just that StarterGui is intended to store the initial state of the User Interface.

This looks like a mix of server and client code, but I’ll save that for another question.

1 Like

This will work since it consists of code to be ran client-side only.

Everything in StarterGui is cloned to PlayerGui, so @ZacharyZaxorDDD’s solution should work

PlayerGui is inherently separate from StarterGui. You are doing game.StarterGui, meaning you are altering the initial data state of the player gui, not the current state. You need to access the current ui state by indexing the player with .PlayerGui. This is why your solution will not work. Data from StarterGui does not feed into a player’s screen whatsoever.

local Start = 0
local Time = 10
local RoundLabel = script.Parent
local Blackout = script.Parent.Parent

while task.wait() do
	RoundLabel.Text = "The Round Starts in: "..Time.." Seconds!"
	wait(1)
	Time = Time - 1
	if Time == Start then
		break
	end
end

RoundLabel.Text = "Starting the Round!"
wait(2)
Blackout.Visible = true

Place inside the RoundLabel instance in StarterGui.

I’m aware, but I assume the original poster wanted this to influence the StarterGui not the PlayerGui. Considering his/her reference to StarterGui & not PlayerGui. All I did was change the way the loop was handled (as that is what was causing the issues before & when it was fixed the script worked) any other feedback you should give to the original poster & not me.

unfortunately this doesn’t work(could be because of my gui layout in explorer), however I was able to find a solution, thank you all for your help.

Most likely so, since the references to the Gui objects relied on where the script & those instances were placed.

1 Like