View difference between Paste ID: wJjfQ2HV and Wz9QMNLK
SHOW: | | - or go back to the newest paste.
1
local ds = game:GetService("DataStoreService"):GetDataStore("UserData12") -- UserData can be everything like "PlayerData" etc. It's up to you
2
-- It is the main storage of the player data
3
4
local rewardTime = 0.001 -- This must be in hours. 24 hours = 1 day. 0.001 = 3.6 seconds
5
local rewardBonus = 8000 -- The reward given to the player once they complete the reward time
6
7
game.Players.PlayerAdded:connect(function(player)
8
	local key = "user:"..player.userId -- Unique user id of the player
9
	local folder = Instance.new("Folder",player)
10
	folder.Name = "leaderstats"
11
	local cash = Instance.new("IntValue",folder)
12
	cash.Name = "Money" -- Name of your currency
13-
	cash.Value = 0 -- Starting money of the player
13+
	cash.Value = 5000 -- Starting money of the player
14
	local increment = Instance.new("IntValue",player)
15
	increment.Name = "BonusIncrement"
16
	increment.Value = 0
17
	
18
	local save
19
	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.
20
		save = ds:GetAsync(key)
21
	end)
22
	if save then
23
		if (os.time()-save.rewardWait)/3600 >= rewardTime then
24
			save={cash=save.cash+(rewardBonus+save.increment);rewardWait=os.time();increment=save.increment+rewardBonus}
25
			ds:SetAsync(key,save)
26
		end
27
		cash.Value = save.cash
28
		increment.Value = save.increment
29
	else
30
		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.
31
	end
32
end)