-
What do you want to achieve? Keep it simple and clear!
I want to use a datastore countdown, I am having trouble getting a table part of a datastore key. I also want to achieve so when i press save on “DataStore Editor V3”, it publishes it live to the countdown I’m making so I don’t have to shutdown the server. -
What is the issue? Include screenshots / videos if possible!
I can’t code it -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
YT, etc
For countdown systems generally I’d save os.time() + howLongInSeconds
in a datastore.
You should be able to store a table in the datastore, however you won’t be able to store a function and won’t be able to store a dictionary. So you’ll need to do something different in order to have your countdown do something. (Potentially calling remote code via require?) I would then use MessagingService in order to update all of my games.
local DataStoreService = game:GetService("DataStoreService");
local datastore = DataStoreService:GetDataStore("Countdown");
local countdown = nil;
local function showCountdown()
countdown = datastore:GetAsync("Countdown") - os.time()
while countdown do
countdown -= 1;
task.wait(1)
end
end
MessagingService:SubscribeAsync("Countdown", function()
showCountdown();
end)
if datastore:GetAsync("Countdown") > os.time() then
showCountdown();
end
-- To create a countdown
-- datastore:SetAsync('Countdown', {os.time() + 3600, 'someValueOrSomething'})
-- MessagingService:PublishAsync("Countdown");