How would I make a daily reward system

So I am trying to make it so that if you touch a BRICK it will give you the reward but it gives you once then you wait 24 hours to get your next reward.

use tick() and datastores for this. When the player touches the brick, check if they have a save or not

local last = ds:GetAsync(plr.UserId) or 0

and check if it has been enough time

if tick() - last >= 86400 then
    --daily reward
end

and save the current tick.

if tick() - last >= 86400 then
    ds:SetAsync(plr.UserId, tick())
    --daily reward
end

You could use the os.time() to make this
I don’t remember the exact functions now but will work like this

If FirstTime = true then β†’ Can take reward

Timer = os.time() --The acutal time when the player touched the brick

Then if the on.time() difference between actual time and timer is >= 3600*24 then β†’ Can take reward and then Timer = os.time() actual time

Hey guys so I tried to make my own system but the player can still get money even after touching it and yeah. Also the gui that says you have already claimed shows for everyone in game not just 1 person
Script:

--local script checks if owns
local Reward = game.ReplicatedStorage.Events.RewardEvents.Reward:InvokeServer(os.date("%j%Y"))
local player = game.Players.LocalPlayer

if Reward then
	print(player.Name.." can collect the daily reward")
	game.Workspace.DailyChest.ClaimTextPart.billboard.subtext.Text = "You can now claim you're reward!"
else
	print(player.Name.." already claimed reward")
	game.Workspace.DailyChest.DailyReward1.Touched:Connect(function()
		player.PlayerGui.Currency.DailyReward.Frame.Visible = true
		player.PlayerGui.Currency.DailyReward.Frame.TextLabel.Text = "You have already claimed you're reward!"
	end)
	game.Workspace.DailyChest.ClaimTextPart.billboard.subtext.Text = "Come back soon for you're next reward!"
end
-- claim event local script
local player = game.Players.LocalPlayer

game.ReplicatedStorage.Events.RewardEvents.ClaimEvent.OnClientEvent:Connect(function()
	game.Workspace.DailyChest.ClaimTextPart.billboard.subtext.Text = "Ready to Claim!"
	game.Workspace.DailyChest.DailyReward1.Touched:Connect(function()
		player.PlayerGui.Currency.DailyReward.Frame.Visible = true
		player.PlayerGui.Currency.DailyReward.Frame.TextLabel.Text = "You claimed you're daily reward!!"
		player.leaderstats.Cash.Value += math.random(10,200)
		game.ReplicatedStorage.Storage.DailyReward2.Parent = game.Workspace.DailyChest
		game.Workspace.DailyChest.DailyReward1.Parent = game.ServerStorage
		game.Workspace.DailyChest.ClaimTextPart.billboard.subtext.Text = "Come back soon for you're reward!"
	end)
end)

-- Server script
local datastore = game:GetService("DataStoreService"):GetDataStore("RewardDS")

game.ReplicatedStorage.Events.RewardEvents.Reward.OnServerInvoke = function(player, date)
	if datastore:GetAsync(player.UserId) ~= date then 
		datastore:UpdateAsync(player.UserId, function(old)
			local new = old or 0
			new = date
			return new
		end)

		game.ReplicatedStorage.Events.RewardEvents.ClaimEvent:FireClient(player)

		return true
	elseif datastore:GetAsync(player.UserId) == nil then
		datastore:SetAsync(player.UserId, date)

		game.ReplicatedStorage.Events.RewardEvents.ClaimEvent:FireClient(player)

		return true
	else
		return false
	end
end
1 Like