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