How to fix my daily rewards timer?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am trying to make my daily rewards timer script display the correct time left.

  1. What is the issue? Include screenshots / videos if possible!

Everything works fine up until I attempt to change the timeleft value inside the player after it is false. I use a system that makes the server makes an int value with the seconds left on the timer inside the player and the local player reads that and displays it reducing the need for remote events. I can get the countdown fine but after the default chest value inside the table is turned false signifying the reward is now avaliable I attempt to change it back and restart the timer but when I do that the timer goes down from -24 hours intead of starting back at a positive 24 hours instead.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have looked all over but cant find any answers on discord or any other resources.

NOTE: please ignore the datastore code I havent finished that yet

local RewardsStore = game:GetService("DataStoreService"):GetDataStore("RewardStore")

local HttpService = game:GetService("HttpService")

local DailyChests = workspace:WaitForChild("DailyChests")

game.Players.PlayerAdded:Connect(function(player)
	local key = "Player-"..player.UserId
	
	local RewardData = RewardsStore:GetAsync(key) or nil

	local ChestTime = player:WaitForChild("leaderstats").ChestTime

	local timeNow = os.time()

	spawn(function()
		while wait(1) do
			local amount = os.time()
			for _,chest in pairs(DailyChests:GetChildren()) do
				if not HttpService:JSONDecode(ChestTime.Value)[chest.Name] == false then
					local waitTime = chest.WaitTime.Value
					local chestAmount = chest.Amount.Value
				
					local timeSinceClaim = os.difftime(amount, timeNow)
					
					local timeLeftInSeconds = math.ceil((waitTime * 3600) - timeSinceClaim)
						
					local newTable = HttpService:JSONDecode(ChestTime.Value)

					if timeLeftInSeconds == -1 then
						newTable[chest.Name] = false
						ChestTime.Value = HttpService:JSONEncode(newTable)
						wait(2)
						newTable[chest.Name] = waitTime
						ChestTime.Value = HttpService:JSONEncode(newTable)
					else
						newTable[chest.Name] = timeLeftInSeconds
						ChestTime.Value = HttpService:JSONEncode(newTable)
					end
				end
			end
		end	
	end)
end)