How to make a timed reward system in the most efficient way?

Hi! I started to make a timed chest for my simulator game but I do not know what to do next or how I should do it in the most effective way. I am trying to make a chest that gives rewards every 24 hours and it also updates a gui to show how long you have got left. Here is a script in the chest.

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("ChestDataStore1")
local coolDown = 24 -- Hours until chest can be opened

local function giveCrowns(plr)
	local amount = 100
        plr.leaderstats.Crowns.Value += amount
end

local function updateGui(num)
	while wait(1) do
		num -= 1
		--UPDATE GUI
	end
end

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			local lastTimeOpened = DS:GetAsync("plr_".. plr.UserId) or nil -- previousTime or nil
			if lastTimeOpened then
				local difference = os.time() - lastTimeOpened
				if difference > coolDown * (60 * 60) then
					DS:SetAsync("plr_".. plr.UserId, os.time())
					giveCrowns()
					updateGui(coolDown * (60 * 60))
				end
			else 
				DS:SetAsync("plr_".. plr.UserId, os.time())
				giveCrowns()
				updateGui(coolDown * (60 * 60))
			end
		end
	end
end)

What’s wrong with your script as it is?

Edit: I made this post talking about the same thing if it’s useful to you: Run A Function Every 24 Hours - #2 by nicemike40

Hi, its not that the script is wrong, it is that I do not know how to move on with what I’ve got. Is it possible if you can show me step-by-step on how to do it?