Which services do I need to do a daily reward system?
✓ ANSWER ACCEPTED
Daily Reward System. How to make it?
1 answer
✓ Accepted answer
You can use os.time()
local rewardTime = 24 -- one day
local rewardAmmount = 50--they get 50 cash each day
local dataStore = game:GetService("DataStoreService"):GetDataStore("dailyRewards")
-- we need a leaderboard
game:GetService("Players").PlayerAdded:Connect(function(player)
local ls = Instance.new("Model")
ls.Name = "leaderstats"
ls.Parent = player
local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Parent = ls
local playerData = nil
pcall(function() -- no errors pls
playerData = dataStore:GetAsync("player_" .. player.UserId)
end)
if playerData then
if ((os.time() - playerData) / (60 * 60)) >= rewardTime then
cash.Value = playerData + rewardAmmount
dataStore:SetAsync(player.UserId, os.time())
else
cash.Value = playerData
end
else
dataStore:SetAsync(player.UserId, os.time())
end
end)
Note: It does not work in Studio unless API Services is enabled and cash does not save, to save, add a PlayerRemoving event.
3 comments
0
Sorry if it didn't work for you.
0
taken from the wiki xd
0
lol what wiki
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
You can use os.time()
and datasoreservice
What is the UNIX, is it a date that I choose or it's the date in the example.
os.time() returns how many seconds since the epoch (1 January 1970, 00:00:00), under UTC time.
os.time() can be vulnerable sometimes, since a person could change the computer's data and time. If you would like to risk timezone time, you could use tick()