Daily reward not working

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 want to achieve a daily reward system. It works for 24Hours… but then the counter hits 00:00:00 and starts going up again? Also it didn’t even give me my reward…
  2. What is the issue? Include screenshots / videos if possible!
    The issue is above
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I had a whole thread about it but I thought it was solved
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- client side
local container  = script.Parent
local Icon = require(container.Icon)
local dropdown = {
	Icon.new()
	:setLabel("Show/Hide Country Flag (For me)")
	:bindEvent("selected", function(icon)
			game.Players.LocalPlayer.Character:WaitForChild("Head"):FindFirstChild(game.Players.LocalPlayer.Name.."CountryBillboardGUI").ImageLabel.Visible = false
	end)
	:bindEvent("deselected", function(icon)
			game.Players.LocalPlayer.Character:WaitForChild("Head"):FindFirstChild(game.Players.LocalPlayer.Name.."CountryBillboardGUI").ImageLabel.Visible = true
	end),

	Icon.new()
		:setLabel("Show/Hide Country Flag (For everyone)")
		:bindEvent("selected", function(icon)
		 game:GetService("ReplicatedStorage").HideCountryFlag:FireServer()
		end)
		:bindEvent("deselected", function(icon)
			game:GetService("ReplicatedStorage").ShowCountryFlag:FireServer()
		end)
	
	
}




Icon.new()
	:setLabel("Settings")
	:setImage(16086868244, "Deselected")
	:setImage(16086868447, "Selected")
    :setDropdown(dropdown)
Icon.new()
	:setLabel("Summon bricks!")
	:bindEvent("selected", function(icon)
		game.Players.LocalPlayer.PlayerGui.Help.BetterUI.Visible = true
	end)
	:bindEvent("deselected", function(icon)
		game.Players.LocalPlayer.PlayerGui.Help.BetterUI.Visible = false
	end)
Icon.new()
	:setLabel("Shop")
	:bindEvent("selected", function(icon)
		game.Players.LocalPlayer.PlayerGui.Menu.ScrollingFrame.Visible = true
	end)
	:bindEvent("deselected", function(icon)
		game.Players.LocalPlayer.PlayerGui.Menu.ScrollingFrame.Visible = false
	end)

Icon.new()
	:setLabel("Claim Daily Reward!")
	:bindEvent("selected", function(icon)
		game.ReplicatedStorage.DailyReward:FireServer()
	end)
--server side
local DataStoreService = game:GetService("DataStoreService")

local DailyRewardDataStore = DataStoreService:GetDataStore("DailyReward")

game.ReplicatedStorage.DailyReward.OnServerEvent:Connect(function(player)
	pcall(function()
		local foundData = DailyRewardDataStore:GetAsync(player.UserId)
		if foundData then
			if tonumber(foundData) < os.time() - 86400 then
				print(player.Name.." is receiving their daily reward")

				player.leaderstats.Brix.Value += 100

				DailyRewardDataStore:SetAsync(player.UserId,os.time())
			else
				print(player.Name.."Is trying to claim their reward early!")
				game.ReplicatedStorage.EventForHMS:FireClient(player,tonumber(foundData))
				 -- seconds
			end
		else
			print(player.Name.." is receiving their first daily reward")
			player.leaderstats.Brix.Value += 100
			DailyRewardDataStore:SetAsync(player.UserId,os.time())
			game.ReplicatedStorage.EventForHMS:FireClient(player,tonumber(foundData))

		end
	end)
end)

-- client 2
game.ReplicatedStorage.EventForHMS.OnClientEvent:Connect(function(foundData)
	local function toHMS(s)
		return ("%02i:%02i:%02i"):format(s/60^2, s/60%60, s%60)
	end
	
script.Parent.TextLabel.Text = toHMS( math.abs(os.difftime(math.abs(os.time()), math.abs(foundData)) - 84600))

end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Also is there any way to edit dataStore so I don’t need to wait 24 hours to see if it works?

There are plugins available which allow you to edit datastores.
I use a paid plugin, but this free plugin should have the same functionality!


Regarding your issue with the daily reward - I’ll do a bit of testing and reply with a solution.

Regarding your issue, I believe this line is this issue:

script.Parent.TextLabel.Text =  = toHMS( math.abs(os.difftime(math.abs(os.time()), math.abs(foundData)) - 84600))

You should force it to be at its lowest 0, which can be achieved using math.max()

You seem to have quite a few unneccessary function calls in the line as well, so I’ve reduce it down a bit:

script.Parent.TextLabel.Text = toHMS(math.max(0, os.time - foundData - 84600))
1 Like