I've been trying to do this for awhile and its been aggravating me. I've looked into daily reward scripts that give a reward daily but don't save cash that has been bought. Here is a script that saves cash but how would i be able to implement os.time() into this?
local DataStore = game:GetService('DataStoreService')
local DSService = DataStore:GetDataStore("PlayerData")
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('Folder', plr)
local savevalue = Instance.new('IntValue')
leaderstats.Name = 'stats'
savevalue.Parent = leaderstats
savevalue.Name = 'Cash'
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.stats.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
