Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ds = game:GetService("DataStoreService"):GetDataStore("UserData12") -- UserData can be everything like "PlayerData" etc. It's up to you
- -- It is the main storage of the player data
- local rewardTime = 0.001 -- This must be in hours. 24 hours = 1 day. 0.001 = 3.6 seconds
- local rewardBonus = 8000 -- The reward given to the player once they complete the reward time
- game.Players.PlayerAdded:connect(function(player)
- local key = "user:"..player.userId -- Unique user id of the player
- local folder = Instance.new("Folder",player)
- folder.Name = "leaderstats"
- local cash = Instance.new("IntValue",folder)
- cash.Name = "Money" -- Name of your currency
- cash.Value = 0 -- Starting money of the player
- local increment = Instance.new("IntValue",player)
- increment.Name = "BonusIncrement"
- increment.Value = 0
- local save
- pcall(function() -- What this does is if there is an error. It will not be called and the script would not break but instead continue to execute the script.
- save = ds:GetAsync(key)
- end)
- if save then
- if (os.time()-save.rewardWait)/3600 >= rewardTime then
- save={cash=save.cash+(rewardBonus+save.increment);rewardWait=os.time();increment=save.increment+rewardBonus}
- ds:SetAsync(key,save)
- end
- cash.Value = save.cash
- increment.Value = save.increment
- else
- ds:SetAsync(key,{cash=0;increment=0;rewardWait = os.time()}) -- The value of the cash here must be the same as the starting cash on top. For example if you have 20 starting cash, the value here must also be 20.
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement