Why won't this work, with no errors?

I’m making a gui that shows intermission and round time, but won’t work with no errors. Script:

local TimeGui = game.StarterGui.TimeGui
local RestartEvent = game.ReplicatedStorage.Restart
while true do
	TimeGui.Frame.TextLabel.Text = "Intermission: 15"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 14"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 13"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 12"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 11"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 10"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 9"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 8"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 7"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 6"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 5"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 4"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 3"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 2"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 1"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 20"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 19"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 18"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 17"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 16"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 15"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 14"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 13"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 12"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 11"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 10"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 9"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 8"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 7"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 6"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 5"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 4"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 3"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 2"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 1"
	wait(1)
end

You could shorten this, cause the code is a bit repetitive. (Might fix it.)

2 Likes

It’s functioning fine, the issue is that StarterGui’s descendants are only replicated to the client’s PlayerGui on spawn (or only on first spawn if ResetOnSpawn is false).

I recommend either reaching it through script.Parent etc or getting the LocalPlayer and accessing it’s PlayerGui.

FYI: A numerical for loop can be used here to count down:

for i = 10, 1, -1 do --// 10 = Start, 1 = Finish, -1 = Deincrementor Identify i as the number counting down
    --// Code
end

I’m not sure how I can do this a shorter way, because I tried

local TimeGui = game.StarterGui.TimeGui
local RestartEvent = game.ReplicatedStorage.Restart
local IntermissionTime = 30
local RoundTime = 25
while wait(1) do
	TimeGui.Frame.TextLabel.Text = IntermissionTime
	IntermissionTime = IntermissionTime - 1
end

and it didn’t work

Just change local TimeGui
To game.Players.LocalPlayer.PlayerGui.TimeGui

Is this script located inside the GUI? If not, where is it located?

It’s located in serverscriptservice

that one didn’t work gave error 18:38:48.846 - ServerScriptService.Script:1: attempt to index nil with ‘PlayerGui’

@SadWowow21 Make it a local script in the TimeGui, then define TimeGui by using this.

local TimeGui = script.Parent

Do what @ReturnedTrue mentioned.

for i = 15,0,-1 do

TimeGui.Frame.TextLabel.Text = i

Oh,well, incase you want to do like yours make like this:


local RestartEvent = game.ReplicatedStorage.Restart
while true do
for i,v in ipairs(game.Players:GetPlayers()) do
local TimeGui = v.PlayerGui:FindFirstChild('TimeGui')
if TimeGui then
	TimeGui.Frame.TextLabel.Text = "Intermission: 15"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 14"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 13"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 12"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 11"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 10"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 9"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 8"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 7"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 6"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 5"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 4"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 3"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 2"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 1"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 20"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 19"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 18"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 17"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 16"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 15"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 14"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 13"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 12"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 11"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 10"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 9"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 8"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 7"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 6"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 5"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 4"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 3"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 2"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 1"
	wait(1)
end
end
wait()
end

NOTE this method isn’t really effective, just basing on yours!

1 Like

This wouldn’t work because he wants a loop.

I did

local TimeGui =  game.StarterGui.TimeGui
local RestartEvent = game.ReplicatedStorage.Restart
for i = 15, 0, -1 do
	TimeGui.Frame.TextLabel.Text = i
end

and the text label just says 0

Here is the solution:

It says 0 because you didn’t add a wait, my bad for not mentioning it.

local RestartEvent = game.ReplicatedStorage.Restart
for i = 15, 0, -1 do
	TimeGui.Frame.TextLabel.Text = i
wait(1)
end

Try that.

1 Like

It worked, and I did

local TimeGui = script.Parent
local RestartEvent = game.ReplicatedStorage.Restart
while true do
	for i = 15, 0, -1 do
		TimeGui.Frame.TextLabel.Text = i
	wait(1)
   end
end

to make it loop. Is there a way that I can do

RestartEvent:Fireclient

after it is done?

He isn’t defining the TimeGui correctly he’s defining it in a Script and not LocalScript he needs to do this:

What’s the difference of putting it in a local script then a script?

its’s a loop.
|| 30charss || aa

GUI’s are local. Place a local script inside the TimeGui, and paste this code into it.

local player = game.Players.LocalPlayer
local TimeGui = script.Parent
local RestartEvent = game.ReplicatedStorage.Restart
RestartEvent:FireAllClients()
RestartEvent.OnClientEvent:Connect(function()
	TimeGui.Frame.TextLabel.Text = "Intermission: 15"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 14"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 13"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 12"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 11"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 10"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 9"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 8"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 7"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 6"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 5"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 4"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 3"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 2"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Intermission: 1"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 20"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 19"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 18"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 17"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 16"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 15"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 14"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 13"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 12"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 11"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 10"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 9"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 8"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 7"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 6"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 5"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 4"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 3"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 2"
	wait(1)
	TimeGui.Frame.TextLabel.Text = "Round: 1"
	wait(1)
    RestartEvent:FireClient(player)
end)
1 Like