Try to kill previous timer while avoiding to affect my other timer

I’m making a calendar reward system in which the principle will be that you have 48 hours but you can only claim the at 23 hours 59 minutes 59 seconds in which then if it goes to 0 all your calendar reward will be reset to 0. So basically what I’m trying to achieve is that when the timer goes to 0 it stops running but at the same time if I reset the timer I want it to kill the previous reward timer to run the new one at 48 hours. Problem is 2 timer persist while I’m claiming the second reward and it’s an issue I’ve been dealing with for hours that I don’t know how to fix I tried using break statement I tried setting boolean conditions.

Here’s the video for example (edit timer now actually doesn’t reset) :

Here’s the code I tried :


function RunTimer(numberSeconds, desc, text, week, day)
	for seconds = 1, numberSeconds do
		if isInRunningLoop == true then
			RemainingSeconds = 0
			break
		else
			RemainingSeconds = numberSeconds - seconds

			if RemainingSeconds > 600 then
				TimerIcon.ImageColor3 = Color3.fromRGB(255, 0, 0)
				TimeRemainingCalendar.TextColor3 = Color3.fromRGB(255, 0, 0)
			else
				TimerIcon.ImageColor3 = Color3.fromRGB(10, 145, 3)
				TimeRemainingCalendar.TextColor3 = Color3.fromRGB(10, 145, 3)
				game.ReplicatedStorage.RewardEvent.CalendarFrame.CanClaimReward:FireServer(week, day+1)
			end

			print("REMAINING SECONDS IN CALENDAR IS : " .. RemainingSeconds)

			text = desc .. FormatTime(RemainingSeconds)
			TimeRemainingCalendar.Text = text

			if RemainingSeconds == 0 and not isInRunningLoop then
				TimeRemainingCalendar.Text = "48:00"
				TimeRemainingCalendar.TextColor3 = Color3.fromRGB(0, 0, 0)
				TimerIcon.ImageColor3 = Color3.fromRGB(0, 0, 0)
				game.ReplicatedStorage.RewardEvent.CalendarFrame.ResetRewards:FireServer()
			end
			
			if RemainingSeconds == 0 and isInRunningLoop then
				RunTimer(numberSeconds, desc, text, week, day)
			end

			wait(1)
		end
	end
end

ClaimCalendar Code :

game.ReplicatedStorage.RewardEvent.CalendarFrame.ClaimCalendar.OnServerEvent:Connect(function(player, week, day)
	print("PLAYER HAS STARTED THE CALENDAR TIMER")
	print("CALENDAR DAY IS : " .. day)
	
	
	if Profiles[player].Data.CalendarTasks["Week" .. week]["Day" .. day].CanBeClaimed == true then
		local ActualTime = os.time()
		
		Profiles[player].Data.TotalClaimed += 1
		Profiles[player].Data.CalendarTasks["Week" .. week]["Day" .. day].CanBeClaimed = false
		Profiles[player].Data.CalendarTasks["Week" .. week]["Day" .. day].Claimed = true

		player:WaitForChild("TotalClaimed").Value = Profiles[player].Data.TotalClaimed
		
		if #Profiles[player].Data.TimeClaimed > 0 then
			game.ReplicatedStorage.RewardEvent.CalendarFrame.ResetTimer:FireClient(player, MAXIMUM_CALENDAR_REWARD_TIME, "", "", week, day)
			table.clear(Profiles[player].Data.TimeClaimed)
			table.insert(Profiles[player].Data.TimeClaimed, ActualTime)
		else
			table.insert(Profiles[player].Data.TimeClaimed, ActualTime)
		end
		
		
		game.ReplicatedStorage.RewardEvent.CalendarFrame.CanClaimReward:FireClient(player, week, day, 	Profiles[player].Data.CalendarTasks["Week" .. week]["Day" .. day].CanBeClaimed)
	
		CalendarRewardManager:RunTimer(player, MAXIMUM_CALENDAR_REWARD_TIME, "", "", week, day)
	end
	
end)

From what I understand, you just want to reset the timer back to 48 hrs when it reaches 0?…

Well basically when the timer text is in green that means I can claim the next day alright and then when I claim the next day I want it to restart my 48 hours when the timer reaches 0 before I claim another reward every reward will be reset on day 1 basically

Alright now problem is when I claim another reward the timer just stop completely instead of starting again at the same time 11 minutes 40 for the test to see if everything’s good

Wait this is kinda confusing, so you want to give the player 48 hours total to be able to claim a reward, but the reward can be claimed only after being unlocked and waiting for 24 hours? So like you claim a reward, wait 24 hours for it to be unlocked, then there’s a 48 hour window to claim it and then when you claim the reward, the next one gets locked on a 24 hour timer and it repeats that loop?

Basically during the first 24 hour of the first 48 hour the reward of the next day is locked but when it passes below the 23h 59 minutes and 59 seconds the player can claim the reward for the next day then when the player claim the reward the 48 hours countdown start again and the player has to wait another 24 hours to claim the reward again for the next day and yeah the loop repeat itself

1 Like

Can’t you just get the start time (when player claims reward) and then from there, add 172800 seconds (48 hours) to the start time and check if the player claimed within that time? Or am I missing something?

Look at claim Calendar. Also here’s the way to check when a player joined the game again :

if Profiles[player].Data.TimeClaimed[1] ~= nil then
				if currentTime - Profiles[player].Data.TimeClaimed[1] >= MAXIMUM_CALENDAR_REWARD_TIME then
					table.clear(Profiles[player].Data.TimeClaimed)

					print("TIMER RESET ITSELF")
					
					Profiles[player].Data.CalendarTasks["Week1"]["Day1"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day1"].CanBeClaimed = true
					Profiles[player].Data.CalendarTasks["Week1"]["Day2"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day2"].CanBeClaimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day3"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day3"].CanBeClaimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day4"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day4"].CanBeClaimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day5"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day5"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week1"]["Day6"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day6"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week1"]["Day7"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week1"]["Day7"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week2"]["Day1"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week2"]["Day1"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week2"]["Day2"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week2"]["Day2"].CanBeClaimed = false

					
					Profiles[player].Data.CalendarTasks["Week2"]["Day3"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week2"]["Day3"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week2"]["Day4"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week2"]["Day4"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week2"]["Day5"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week2"]["Day5"].CanBeClaimed = false

					
					Profiles[player].Data.CalendarTasks["Week2"]["Day6"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week2"]["Day6"].CanBeClaimed = false

					
					Profiles[player].Data.CalendarTasks["Week2"]["Day7"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week2"]["Day7"].CanBeClaimed = false

					
					Profiles[player].Data.CalendarTasks["Week3"]["Day1"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week3"]["Day1"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week3"]["Day2"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week3"]["Day2"].CanBeClaimed = false

					
					Profiles[player].Data.CalendarTasks["Week3"]["Day3"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week3"]["Day3"].CanBeClaimed = false

					
					Profiles[player].Data.CalendarTasks["Week3"]["Day4"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week3"]["Day4"].CanBeClaimed = false

					
					Profiles[player].Data.CalendarTasks["Week3"]["Day5"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week3"]["Day5"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week3"]["Day6"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week3"]["Day6"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week3"]["Day7"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week3"]["Day7"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week4"]["Day1"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week4"]["Day1"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week4"]["Day2"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week4"]["Day2"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week4"]["Day3"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week4"]["Day3"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week4"]["Day4"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week4"]["Day4"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week4"]["Day5"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week4"]["Day5"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week4"]["Day6"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week4"]["Day6"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week4"]["Day7"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week4"]["Day7"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week5"]["Day1"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week5"]["Day1"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week5"]["Day2"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week5"]["Day2"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week5"]["Day3"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week5"]["Day3"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week5"]["Day4"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week5"]["Day4"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week5"]["Day5"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week5"]["Day5"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week5"]["Day6"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week5"]["Day6"].CanBeClaimed = false

					Profiles[player].Data.CalendarTasks["Week5"]["Day7"].Claimed = false
					Profiles[player].Data.CalendarTasks["Week5"]["Day7"].CanBeClaimed = false

				else
					CalendarRewardManager:RunTimer(player, MAXIMUM_CALENDAR_REWARD_TIME - (currentTime - Profiles[player].Data.TimeClaimed[1]),  "", "", Profiles[player].Data.CurrentWeekProgression, Profiles[player].Data.CurrentDayProgression)
				end
			end

also the way our system work is basically its about a calendar reward. theres 30 days in total. So when you start playing the game the first time, at day one you can claim your presence reward. when you claim it, You’ll have to wait 24 h, so tomorrow you can claim it again, but I want to add a 24h of chances for him to claim the 2nd day. so he has all day to claim day 2. If he claim it before 0h00. he will be able to do the 3rd day tomorrow. but if he doesnt claim, and it goes down to 0h00. he will have to restart at day 1. that’s why there will be a 48h countdown each time you claim.

Alright problem now is when I claim another reward timer goes down faster but it should go down at same rate I changed the loop structure seems closer to my goal