I’m wondering if there was a way to handle status updates that are essentially the same every round loop. I currently have a function that takes a couple of arguments, but the lines that call the function are quite long.
local function UpdateStatus(Status, Yield, YieldTime)
ReplicatedStorage:SetAttribute('Status', Status)
if Yield then
wait(YieldTime)
end
end
while true do
local Interval = Settings.Interval
local RequiredPlayers = Settings.RequiredPlayers
if #PlayersService:GetPlayers() < RequiredPlayers then
UpdateStatus('Not enough players to start', true, Interval)
continue
end
for Timer = Settings.IntermissionTimer, 1, -1 do
UpdateStatus(('Starting new round %.2d:%.2d'):format(Timer / 60, Timer % 60), true, 1)
end
for Timer = Settings.Grace, 1, -1 do
UpdateStatus(('Grace period %.2d:%.2d'):format(Timer / 60, Timer % 60), true, 1)
end
for Timer = Settings.RoundTimer, 1, -1 do
if #Players <= 1 then
break
end
UpdateStatus(('Time remaining %.2d:%.2d'):format(Timer / 60, Timer % 60), true, 1)
end
if #Players > 1 then
UpdateStatus('Time is up! There is no winner.', true, Interval)
else
local _, Winner = next(Players)
if Winner then
UpdateStatus(('Winner: %s!'):format(Winner.Name), true, Interval)
else
UpdateStatus('There was no winner!', true, Interval)
end
end
end
I removed most of the code that doesn’t call UpdateStatus
.