Timer Script Not Working

Hey Developers!
I was making a timer script for my story game lobby! But I noticed that it wasn’t working…
I am not getting any errors, but the output isn’t printing anything!
Here is my script:

--Variables
local Bus = game.Workspace:WaitForChild('Bus')
local Seats = Bus.Seats
local Hitbox = game.Workspace:WaitForChild('Hitbox')

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local TeleportService = game:GetService('TeleportService')
local ServerStorage = game:GetService('ServerStorage')
local Status = ReplicatedStorage:WaitForChild('Status')
local UI = ServerStorage:WaitForChild('ExitGui')

local MinimumPlayers = 3
local Players = 0
local Time = 30
local Teleporting = false
local BusTable = {}

Hitbox.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and Teleporting == false then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if table.find(BusTable, Player) == nil then
			for _, seat in pairs(Seats:GetChildren()) do
				if seat.Occupant == nil then
					table.insert(BusTable, Player)
					local Humanoid = Player.Character.Humanoid
					Humanoid.JumpPower = 0
					seat:Sit(Humanoid)
					UI:Clone().Parent = Player.PlayerGui
					break
				end
			end
		end
	end
end)

ReplicatedStorage.LeaveBus.OnServerEvent:Connect(function(Player)
	local ReturnValue = table.find(BusTable, Player)
	table.remove(BusTable, ReturnValue)
	Player:LoadCharacter()
	Player.Character:WaitForChild('HumanoidRootPart').CFrame = game.Workspace.Setback.CFrame
end)

while true do
	wait()
	for i = 1, Time, -1 do
		print(i)
		wait(1)
	end
end

Thanks for any help!
I am trying to make a timer countdown, but it isn’t even printing the time!

Hey,

Does it perhaps say in yellow in the output, “Infinite yield on…”, this means that :WaitForChild() is waiting indefinitely for something that does not exist. Perhaps check the names of the things you are waiting for with this method.

No, it doesn’t…
Everything else works, apart from the timer script…

I see the error.

Your problem is with the for loop.

When counting DOWN, you must provide the first parameter as the Time Variable, rather than the starting position. It should be in the format for i = Time, 1, -1, rather than for i = 1, Time, -1.

1 Like