Got a strange problem here. I have a rounds system in my game. The first timer counts down the Intermission time, from 30 to 1, teleport the players to the map, where the Round Timer kicks in. Except, instead of subtracting every second, it takes three seconds for the timer to decrease by one. I'm confused since the Intermission timer works fine, and this did not use to happen.
This seems to be causing my game to lag on the server, I sometimes get a "timeout before resuming thread" error, but I assume that's because my script is an infinite loop? Is there a more efficient way to have my countdown timers here that doesn't trigger the timeout error?
Here's the Intermission/Round Timer script info below:
local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('InfoValue')
local mapstorage = game.workspace:WaitForChild('mapStorage')
local StarterGui = game:GetService('StarterGui')
while true do
wait(1)
while game.Players.NumPlayers < 2 do
status.Value = 'There needs to be 2 or more players to play!'
repeat wait(2) until game.Players.NumPlayers >= 2
end
--INTERMISSION TIMER
wait(1)
for i = 30,0,-1 do
status.Value = 'Party Break '..i
wait(1)
end
_G.gameplayers = {}
for i, v in pairs(game.Players:GetPlayers()) do
if v then
table.insert(_G.gameplayers, v.Name)
end
end
-- Random Map selection & Spawns
local mapsinserverstorage = game:GetService('ServerStorage').Maps:GetChildren()
local chosenmap = mapsinserverstorage[math.random(1,#mapsinserverstorage)]
chosenmap:Clone().Parent = mapstorage
status.Value = 'Get ready to be teleported!'
wait(3)
local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
for _, player in pairs(game.Players:GetPlayers()) do
if player and #spawns > 0 then
local torso = player.Character:WaitForChild('Torso')
local allspawns = math.random(1, #spawns)
local randomspawn = spawns[allspawns]
if randomspawn and torso then
table.remove(spawns, allspawns)
torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
end
end
end
-- ROUNDS TIMER
for i = 240, 0, -1 do
if i == 0 then
status.Value = 'Time up!'
break
end
wait(2)
if #_G.gameplayers == 1 then
for i, v in pairs (_G.gameplayers) do
if v ~= nil then
status.Value = v..' is the winner!'
game.Players[v].leaderstats.Wins.Value = game.Players[v].leaderstats.Wins.Value + 1
break
end
end
break
else
status.Value = i..' seconds remaining!'
end
end
mapstorage:ClearAllChildren()
wait(3)
end

3 comments
Why in the world would you nest a repeat inside a while loop inside an infinite while loop?! All this could be done with a single loop
It worked just fine in the Studio setting, never had problems before, but im certainly open to suggestions on how to fix it. :) thank you!
Anyone else want to try this?