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)