Well I always wondered how developers make daily systems like daily rewards
3 Likes
You can use datastores to log when a player claims their reward and then compare that time to the next time the player logs in to see if they qualify for for the daily reward. Example:
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DailyRewardRemote = ReplicatedStorage.RemoteEvent
local DailyRewardDataStore = DataStoreService:GetDataStore("DailyRewardDataStore")
DailyRewardRemote.OnServerEvent:Connect(function(player) -- example remote call
local Time = DailyRewardDataStore:GetAsync(player.UserId) -- gets last write to the datastore
if not Time or (os.time() - Time) > 86400 then -- checks if the last time the player got their reward has been over 24 hours
-- grant reward here
DailyRewardDataStore:SetAsync(player.UserId, os.time()) -- writes new time of daily reward claim
else
-- do not grant reward here
end
end)
Please note that the script above is just an example of how a daily reward system would work and if you plan on using it for a game then remember to add datastore failure mitigation.
18 Likes
thank you perfect explanation
Thank you for this daily reward script, Iām dying searching for this
1 Like