I posted this not long time ago, and i received this script right here. I edited him a little bit for my use. But now, i have some questions about it. I'd like to create a UI with the amount of time before the reward. So i tried to send back the value of the PlayerData to get the time, but since she send me this in the output.
function: 16E5BAC4
--< Services local PlayerService = game:GetService('Players') local DataStoreService = game:GetService('DataStoreService') --< Variables local DailyRewards = DataStoreService:GetDataStore('dailyRewards') local RewardTime = 24 -- One day local RewardAmmount = 50 -- They get 50 cash each day local SessionData = {} --< Event PlayerService.PlayerAdded:Connect(function(Player) local ls = Instance.new('Folder') ls.Name = 'leaderstats' ls.Parent = Player SessionData[Player] = {} SessionData[Player]['Cash'] = 100 local Cash = Instance.new('IntValue', ls) Cash.Name = 'Cash' Cash.Value = SessionData[Player]['Cash'] local PlayerData = nil pcall(function() -- No errors pls PlayerData = DailyRewards:GetAsync('player_' .. Player.UserId) end) if PlayerData then if ((os.time() - PlayerData) / (60 * 60)) >= RewardTime then Cash.Value = PlayerData + RewardAmmount DailyRewards:SetAsync(Player.UserId, os.time()) else Cash.Value = PlayerData end else DailyRewards:SetAsync(Player.UserId, os.time()) end end)
idk about your code but here's what you should do
local DataStoreService = game:GetService('DataStoreService') local DailyRewards = DataStoreService:GetDataStore('dailyRewards') game.Players.PlayerAdded:Connect(function(plr) local currentDay = math.floor(os.time()/86400) local key = plr.UserId if DailyRewards:GetAsync(key) then --checks if there is any saved values local oldDay = DailyRewards:GetAsync(key) if oldDay < currentDay then -- give your reward end end DailyRewards:SetAsync(key, currentDay) end)