Os.Time stops running when "Player left"

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.

Is the script located in any place that only exist while the player is in game?

It’s a Server Script. i even wanted to include it at the end of resolving the issue a try something and i comeback with a update.

i don’t understand what you mean please clarify it for me.

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.

So on a Normal server it runs defrently?

Yes, to test if my hypothesis is correct, i suppose you can start a server with 2 players from the Test tab and make one of the players leave.

this has sadly no difference i just tried it with the Roblox Client.

When the player leaves the server, what specifically do you notice stops running?

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! :two_hearts:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.