Here is a countdown script I currently have. I was wondering is this a good way of making a countdown or no?
Uses replicaservice and promises
local activeCountdown = nil
local Countdown = 10
local function StartCountDown(Replica)
-- Cancel any previous countdown if it exists
if activeCountdown then
activeCountdown:cancel() -- Cancels the previous promise/task
activeCountdown = nil
end
-- Create a new promise for the countdown
activeCountdown = Promise.new(function(resolve, reject, oncancel)
Replica:SetValue("Counter", 10)
for count = Countdown, 0, -1 do
-- Check if the countdown is canceled
if oncancel() then
return -- Exit the loop if canceled
end
if Replica.Data.Counter ~= nil then
Replica:SetValue("Counter", count)
-- When the countdown reaches 0
if count == 0 and #Replica.Data.Players > 0 then
end
task.wait(1) -- Wait for 1 second
else
break -- Exit the loop if the Counter is nil
end
end
-- Countdown completed
resolve()
end)
end