Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Daily Reward System. How to make it?

Asked by 5 years ago

Which services do I need to do a daily reward system?

0
You can use os.time() User#22219 20 — 5y
0
and datasoreservice User#20388 0 — 5y
0
What is the UNIX, is it a date that I choose or it's the date in the example. NiniBlackJackQc 1562 — 5y
0
os.time() returns how many seconds since the epoch (1 January 1970, 00:00:00), under UTC time. SulaymanArafat 230 — 5y
0
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() User#22219 20 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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.

0
Sorry if it didn't work for you. User#22219 20 — 5y
0
taken from the wiki xd SulaymanArafat 230 — 5y
0
lol what wiki User#22219 20 — 5y
Ad

Answer this question