I need help with my timer countdown script. (Beginner Scripter)

I am scripting an Intermission/Ingame timer for an FPS that i’m making, but i’m testing the Intermission script, which is almost identical to the Ingame script. During testing, i have found it always sets the number to 29, do you guys know the fix? Here is the code:

local StatusBar = game.StarterGui.TopFrame.Bar
local GameStatus = "Intermission"
local Time = 30

function GetPlayerCount()
	Players = #game.Players:GetPlayers()
end

wait(1)

while true do
	if GameStatus == "InGame" then
		GetPlayerCount()
		if Players == 1 or Time == 0 then
			GameStatus = "Intermission"
			Time = 30
		elseif Players >= 2 or Time >= 0 then
			local Time = Time - 1
			print(Players)
			print(Time)
			print(GameStatus)
			StatusBar.Text = Time
			wait(1)
		end
	elseif GameStatus == "Intermission" then
		GetPlayerCount()
			if Players >= 2 or Time >= 0 then
				local Time = Time - 1
				print(Players)
				print(Time)
				print(GameStatus)
				StatusBar.Text = "INTERMISSION ".. Time
				wait(1)
			elseif Players == 50 or Time == 0 then
				GameStatus = "InGame"
				Time = 300
		end
	end
end

Here is the output:


Note: I have done multiple server tests with different player amounts.

4 Likes

It may be because of

local Time = Time - 1

You should do

Time = Time - 1
4 Likes

So when you’re updating the time (local Time = Time - 1) you’re actually creating a new variable… Remove the local and it should work!

5 Likes

Imma try that, i’ll see what it does.

Thanks for the explanation of that, I actually did not know that it does that!

2 Likes

Thanks for the suggestion guys! It worked!