I need help with data store, coins every hour "DATASTORE2" I wanna make a daily reward but idk how

Help I wanna make the player coins update every hour by 25 points, and have a little notification that pops up but I don’t know how, or make a daily reward by 7 days.


DataStore2.Combine("Key","Coins","Inventory","EquippedWeapon")

-- Default Values
local defaultCoins = 0
local defaultInventory = {}
local defaultEquippedWeapon = ""

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	
	-- Setup
	local coins = Instance.new("IntValue",player); coins.Name = "Coins"
	
	local inventory = Instance.new("Folder",player); inventory.Name = "Inventory"
	local equippedWeapon = Instance.new("StringValue",player); equippedWeapon.Name = "EquippedWeapon"
	
	-- Get DataStores
	local coinsStore = DataStore2("Coins",player)
	local inventoryStore = DataStore2("Inventory",player)
	local equippedWeaponStore = DataStore2("EquippedWeapon",player)
	
	-- Functions
	local function updateCoins(newValue)
		coins.Value = newValue
	end
	
	local function updateInventory(newTable)
		-- Clear
		for i,v in pairs(inventory:GetChildren()) do v:Destroy() end
		
		-- Make a new one
		for i,v in pairs(newTable) do
			local itemValue = Instance.new("BoolValue",inventory); itemValue.Name = v
		end
	end
	
	local function updateEquippedWeapon(newString)
		equippedWeapon.Value = newString
		
		-- Clear
		for i,v in pairs(player.Backpack:GetChildren()) do if v:IsA("Tool") then v:Destroy() end end
		for i,v in pairs(player.StarterGear:GetChildren()) do if v:IsA("Tool") then v:Destroy() end end
		for i,v in pairs(char:GetChildren()) do if v:IsA("Tool") then v:Destroy() end end
		
		-- Equip them
		if game.ReplicatedStorage.Weapons:FindFirstChild(equippedWeapon.Value) then
			game.ReplicatedStorage.Weapons:FindFirstChild(equippedWeapon.Value):Clone().Parent = player.Backpack
			game.ReplicatedStorage.Weapons:FindFirstChild(equippedWeapon.Value):Clone().Parent = player.StarterGear
		end
	end
	
	-- Call functions right away
	updateCoins(coinsStore:Get(defaultCoins))
	updateInventory(inventoryStore:Get(defaultInventory))
	updateEquippedWeapon(equippedWeaponStore:Get(defaultEquippedWeapon))
	
	-- Call functions for updates
	coinsStore:OnUpdate(updateCoins)
	inventoryStore:OnUpdate(updateInventory)
	equippedWeaponStore:OnUpdate(updateEquippedWeapon)
	
	game.ReplicatedStorage.Events.SendData:FireClient(player)
end)

game.ReplicatedStorage.Events.Buy.OnServerInvoke = function(player,itemName)
	
	local char = player.Character
	
	-- Get their data Store
	local coinsStore = DataStore2("Coins",player)
	local inventoryStore = DataStore2("Inventory",player)
	local equippedWeaponStore = DataStore2("EquippedWeapon",player)
	
	local item, inInventory
	
	local newTable = {}
	
	item = game.ReplicatedStorage.Weapons:FindFirstChild(itemName)
	
	if player.Inventory:FindFirstChild(itemName) then inInventory = true end
	
	if item and item:GetAttribute("Price") then
		if not inInventory then
			
			-- If the player brought the item
			if player.Coins.Value >= item:GetAttribute("Price") then
				
				coinsStore:Increment(-item:GetAttribute("Price"))
				
				local itemValue = Instance.new("BoolValue",player.Inventory); itemValue.Name = item.Name
				
				for i,v in pairs(player.Inventory:GetChildren()) do table.insert(newTable,v.Name) end
				
				inventoryStore:Set(newTable)
				
				return "Brought"
			else
				return "NotEnough"
			end
			
		else
			if player.EquippedWeapon.Value ~= item.Name then
				equippedWeaponStore:Set(item.Name)				
				return "Equip"
			else
				equippedWeaponStore:Set("")
				return "Unequip"
			end
			
		end
	end
	
end

This is possible by using tick(). Set a value in the data store that keeps track of the last reward time. 7 days is 604800 seconds. Tick is measured in seconds. So you can subtract the current tick with the login tick, and if it’s greater or equal to 604800, you set the login tick to the current tick, and reward the player.

1 Like