Countdown via datastore stuff

  1. What do you want to achieve? Keep it simple and clear!
    I want to change it to BST and make it stop erroring
  2. What is the issue? Include screenshots / videos if possible!
    I get this error: “Workspace.CountdownTimer.CountdownGui.CountdownHandler:5: field ‘day’ missing in date table”
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Asking friends, YT
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local countdownGui = script.Parent
local countdownText = countdownGui:WaitForChild("CountdownText")



while wait() do
	local day = os.time({year = script.Parent.Script.Year.Value, month = script.Parent.Script.Month.Value, day = script.Parent.Script.Day.Value, hour = script.Parent.Script.Hour.Value, min = script.Parent.Script.Minute.Value, sec = script.Parent.Script.Second.Value})
	local secondsBetween = os.difftime(day, os.time())
	
	local seconds = secondsBetween % 60
	local minutes = math.floor(secondsBetween % (60*60) / 60)
	local hours = math.floor(secondsBetween % (60*60*24) / (60*60))
	local days = math.floor(secondsBetween % (60*60*24*30) / (60*60*24*30))
	
	local textString = days .. "d:" .. hours .. "h:" .. minutes .. "m:" .. seconds .. "s"
	countdownText.Text = textString
	
	if secondsBetween <= 0 then break end
end

I think that the script.Parent.Script.Day.Value may be nil, trying printing that value individually before you define day and see what it prints.

It will not print. Btw, it isn’t the script.Parent.Day.Value. That is the 8th. It’s the table.

-- script 1

-- set a timer for 60 seconds
local timerValue = Instance.new("NumberValue")
timerValue.Name = "Timer"
timerValue.Value = os.time() + 60
timerValue.Parent = game.ReplicatedStorage

-- script 2

local timerValue = game.ReplicatedStorage:WaitForChild("Timer")

local function SecondsToString(seconds)
    local days = math.floor(seconds / 86400)
    local hours = math.floor(seconds % 86400 / 3600)
    local minutes = math.floor(seconds % 3600 / 60)
    seconds = math.floor(seconds % 60)
    return string.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds)
end

while true do
    local deltaTime = timerValue.Value - os.time()
    countdownText.Text = SecondsToString(deltaTime)
    if deltaTime <= 0 then break end
    task.wait(1)
end

The thing is, I’m trying to use it via datastore so I can update it live.

-- script 1

local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("timer")

-- set timer for 60 seconds
local success, value = pcall(dataStore.SetAsync, dataStore, "Key", os.time() + 60)

-- script 2

local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("timer")

local success, value = pcall(dataStore.GetAsync, dataStore, "Key")
if success == false then return end

local function SecondsToString(seconds)
    local days = math.floor(seconds / 86400)
    local hours = math.floor(seconds % 86400 / 3600)
    local minutes = math.floor(seconds % 3600 / 60)
    seconds = math.floor(seconds % 60)
    return string.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds)
end

while true do
    local deltaTime = value - os.time()
    countdownText.Text = SecondsToString(deltaTime)
    if deltaTime <= 0 then break end
    task.wait(1)
end

but if you need to update it quickly it might be better to use
https://developer.roblox.com/en-us/articles/memory-store