Daily Reward 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!
    A Daily Reward Timer

  2. What is the issue? Include screenshots / videos if possible!
    The Timer Freezes / The Timer didn’t change

  3. What solutions have you tried so far?
    Already look on devforum and yt but seems like didnt found any

local DataStoreService = game:GetService("DataStoreService")

local DailyRewardDS = DataStoreService:GetDataStore("NewDailyReward")

local rewardsForStreak = 
	{
		[1] = {5, 0},
		[2] = {10, 0},
		[3] = {15, 0},
		[4] = {25, 50},
		[5] = {40, 100},
	}

game.Players.PlayerAdded:Connect(function(player)
	
	local success, dailyRewardInfo = pcall(function()
		return DailyRewardDS:GetAsync(player.UserId .. "-DailyRewards")
	end)
	if type(dailyRewardInfo) ~= "table" then dailyRewardInfo = {nil, nil, nil} end
	
	local Money = player:WaitForChild("Money")
	local Exp = player:WaitForChild("Exp")
	
	Money.Value = dailyRewardInfo[1] or 0
	
	local lastOnline = dailyRewardInfo[2]
	local CurrentTime = os.time()
	
	local timeDifference
	
	if lastOnline then
		timeDifference = CurrentTime - lastOnline
	end
	
	local ScreenGui = player.PlayerGui:WaitForChild("ScreenGui")
	local DailyRewardsGUI = ScreenGui:WaitForChild("DailyRewards")
	local ClaimButton = DailyRewardsGUI:WaitForChild("ClaimButton")
	local Days = DailyRewardsGUI:WaitForChild("Days")
	local Timer = ScreenGui:WaitForChild("Timer")
		
	local Seconds = CurrentTime - lastOnline
	local Minutes = Seconds / 60
	local Hours = Minutes / 60
	
	local DrValue = Timer:WaitForChild("DrValue")
	
	DrValue.Value = ("Daily Reward: %.2d:%.2d:%.2d"):format(Hours, Minutes%(60), Seconds%(60))
	
	DrValue.Changed:Connect(function()
		Timer.Text = DrValue.Value
	end)
	
	Timer.Text = DrValue.Value

	
	if not timeDifference or timeDifference >= 24*60*60 then
		local streak = dailyRewardInfo[3] or 1
		local reward = rewardsForStreak[streak]
		
		local rewardInfo = rewardsForStreak[streak]
		local coins = rewardInfo[1]
		local exp = rewardInfo[2]
				
		DailyRewardsGUI.Visible = true
		Days.Text = "Day " .. streak
		
		if streak > 5 then streak = 1 end
		
		ClaimButton.MouseButton1Click:Connect(function()
			ClaimButton.Sound:Play()

			Money.Value += coins
			Exp.Value += exp
			
			DailyRewardsGUI.Visible = false
			
			local streak = streak + 1
			
			if streak > 5 then streak = 1 end
			
			local success, errormsg = pcall(function()
				DailyRewardDS:SetAsync(player.UserId .. "-DailyRewards", {Money.Value, os.time(), streak})
			end)
		end)
	elseif timeDifference then
		task.wait((24*60*60) - timeDifference)
		if game.Players:FindFirstChild(player) then
			
			local streak = dailyRewardInfo[3] or 1
			local reward = rewardsForStreak[streak]
			
			local rewardInfo = rewardsForStreak[streak]
			local coins = rewardInfo[1]
			local exp = rewardInfo[2]

			local DailyRewardsGUI = player.PlayerGui:WaitForChild("DailyRewards")
			local ClaimButton = DailyRewardsGUI:WaitForChild("ClaimButton")
			local Days = DailyRewardsGUI:WaitForChild("Days")

			DailyRewardsGUI.Visible = true
			Days.Text = "Days " .. streak
			
			ClaimButton.MouseButton1Click:Connect(function()
				ClaimButton.Sound:Play()

				Money.Value += coins
				Exp.Value += exp
				
				DailyRewardsGUI.Visible = false

				local streak = streak + 1
				
				if streak > 5 then streak = 1 end

				local success, errormsg = pcall(function()
					DailyRewardDS:SetAsync(player.UserId .. "-DailyRewards", {Money.Value, os.time(), streak})
				end)
			end)
		end
	end
end)


2 Likes

This line is the problem

Text Will be blurred

1 Like

Try this script:

local function formatnumber(number)
  local formatted = string.format("%02i",number)
  return formatted
end

timer.Text = formatnumber(hours).." hours and "..formatnumber(seconds)

Refer this link

The Timer still doesnt change

Ignore that errors.

The script I sent runs only 1 time, keep
while wait(1) do if you want the timer script to run every second

Any errors?

image

Run tick() thats the most common way for daily timer

I already put that that but still doesn’t work

And there’s no errors on the output

So I already did that but still doesnt work

Check the link I posted, many tried it and it works, maybe try to do that, post there if you found that not working too

Just checked the post and uhh I think that post is about converting secs to (h:mins:sec)

Yes, so whats your issue in your script?

I wanna fix my daily reward timer that counts down till 0

And when player claims the reward, the timer will resets back to 24 hours

I think the issue may be related to the fact you didn’t type

local lastOnline = dailyRewardInfo[2] or os.time() 

causing the value Seconds to mess up.

Look, just use tick(), os.time() is quite complicated

already tried but still doesn’t work

results is still the same, not working

if type(dailyRewardInfo) ~= "table" then dailyRewardInfo = {nil, nil, nil} end

Shudnt u check for success?