Hey everyone, im currently trying to make a Countdown that continues even when the “Player left”.
Os.Time should normally at my knowledge still run even if the “Player left” i tryd using a normal “Countdown” i think Os.Clock and more so help is highly appreciated!
This script should have the resources to get this working it, counts currently down form “10 Minutes”
local startTime = os.time()
local endTime = startTime + 10 * 60
while os.time() < endTime do
local timeLeft = endTime - os.time()
local minutes = math.floor(timeLeft / 60)
local seconds = timeLeft % 60
print(string.format("Time Left: %02d:%02d", minutes, seconds))
wait(1)
end
print("Time is over!")
like allways i like to say it once again help is highly appreciated! and i hope we can solve this issue now completely since the resources seem to be very low on Os.Time().
Is this a server or local script?
And is the issue that you want the countdown to continue even if the server shuts down or client disconnects (therefore closing the script)?
If it is this you would want to store the start time in the DatastoreService, and get the difference when a new server begins or the client reconnects.
If you are playtesting normally (by clicking Play with a single client) then the server closes as soon as the client leaves or the Stop button is pressed.
With the Comment of @Wigglyaa: i could resolve this issue.
For anyone who was/is facing the same issue as me i want to Contribute this Code so the issue cannot continue in the future:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("MyDataStore")
local key = "EndTime"
local startTime = os.time()
local endTime = myDataStore:GetAsync(key) or (startTime + 10 * 60)
myDataStore:SetAsync(key, endTime)
while os.time() < endTime do
local timeLeft = endTime - os.time()
local minutes = math.floor(timeLeft / 60)
local seconds = timeLeft % 60
print(string.format("Time Left: %02d:%02d", minutes, seconds))
wait(1)
end
print("Time is over!")
myDataStore:RemoveAsync(key)
anyways thanks to everyone contributing to this issue!