View difference between Paste ID: 1GHLuRmu and Nxc79mTn
SHOW: | | - or go back to the newest paste.
1
local dss = game:GetService("DataStoreService")
2
3
local dailyRewardDS = dss:GetDataStore("DailyRewards")
4
5
6
local rewardsForStreak = 
7
{
8
	[1] = 100,
9
	[2] = 250,
10
	[3] = 500,
11
	[4] = 1000,
12
	[5] = 1750,
13
	[6] = 3000,
14
	[7] = 7500,
15
}
16
17
18
game.Players.PlayerAdded:Connect(function(plr)
19
	
20
	local success, dailyRewardInfo = pcall(function()
21
		return dailyRewardDS:GetAsync(plr.UserId .. "-DailyRewards")
22
	end)
23
	if type(dailyRewardInfo) ~= "table" then dailyRewardInfo = {nil, nil, nil} end
24
	
25
	local leaderstats = Instance.new("Folder")
26
	leaderstats.Name = "leaderstats"
27
	leaderstats.Parent = plr
28
	
29
	local cash = Instance.new("IntValue")
30
	cash.Name = "Cash"
31
	
32
	cash.Value = dailyRewardInfo[1] or 0
33
	
34
	cash.Parent = leaderstats
35
	
36
	
37
	local lastOnline = dailyRewardInfo[2]
38
	local currentTime = os.time()
39
	
40
	local timeDifference
41
	
42
	if lastOnline then	
43
		timeDifference = currentTime - lastOnline
44
	end
45
	
46
	if not timeDifference or timeDifference >= 24*60*60 then
47
		
48
		local streak = dailyRewardInfo[3] or 1
49
		local reward = rewardsForStreak[streak]
50
		
51
		local dailyRewardGui = plr.PlayerGui:WaitForChild("DailyRewardGui")
52
		local mainGui = dailyRewardGui:WaitForChild("MainGui")
53
		local claimBtn = mainGui:WaitForChild("ClaimButton")
54
		local rewardLabel = mainGui:WaitForChild("RewardLabel")
55
		
56
		rewardLabel.Text = reward
57
		
58
		dailyRewardGui.Enabled = true
59
		
60
		claimBtn.MouseButton1Click:Connect(function()
61
			
62
			cash.Value = cash.Value + reward
63
			
64
			dailyRewardGui.Enabled = false
65
			
66
			local streak = streak + 1
67
			if streak > 7 then streak = 1 end
68
			
69
			local success, errormsg = pcall(function()
70
				
71
				dailyRewardDS:SetAsync(plr.UserId .. "-DailyRewards", {cash.Value, os.time(), streak})
72
			end)
73
		end)
74
		
75
	elseif timeDifference then
76
		
77
		wait((24*60*60) - timeDifference)
78
		
79
		if game.Players:FindFirstChild(plr) then
80
			
81
			local streak = dailyRewardInfo[3] or 1
82
			local reward = rewardsForStreak[streak]
83
			
84
			local dailyRewardGui = plr.PlayerGui:WaitForChild("DailyRewardGui")
85
			local mainGui = dailyRewardGui:WaitForChild("MainGui")
86
			local claimBtn = mainGui:WaitForChild("ClaimButton")
87
			local rewardLabel = mainGui:WaitForChild("RewardLabel")
88
			
89
			rewardLabel.Text = reward
90
			
91
			dailyRewardGui.Enabled = true
92
			
93
			claimBtn.MouseButton1Click:Connect(function()
94
				
95
				cash.Value = cash.Value + reward
96
				
97
				dailyRewardGui.Enabled = false
98
				
99
				local streak = streak + 1
100
				if streak > 7 then streak = 1 end
101
				
102
				pcall(function()
103
					
104
					dailyRewardDS:SetAsync(plr.UserId .. "-DailyRewards", {cash.Value, os.time(), streak})
105
				end)
106
			end)
107
		end
108
	end
109
end)