Advertisement
Guest User

Roblox Daily Reward

a guest
May 28th, 2019
1,385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. -- All scripts are in ServerScriptService
  2. -- Daily Reward Script; "Script"
  3.  
  4. local DataStore = game:GetService("DataStoreService"):GetDataStore("DailyRewards")
  5.  
  6. local hourWait = 0.0006
  7.  
  8. local possibleRewards = {10,15,10,10,5,5,5,5,5,10,10,15,50}
  9.  
  10. local defaultCash = 0
  11.  
  12. game.Players.PlayerAdded:Connect(function(player)
  13.  
  14. local leaderstats = Instance.new("Folder")
  15. leaderstats.Name = "leaderstats"
  16. leaderstats.Parent = player
  17.  
  18. local coins = Instance.new("IntValue")
  19. coins.Name = "Coins"
  20. coins.Parent = leaderstats
  21.  
  22. local timeNow = os.time()
  23.  
  24. local playerData = Instance.new("Folder")
  25. playerData.Name = player.Name
  26. playerData.Parent = game.ServerStorage.PlayerData
  27.  
  28. local data
  29.  
  30. pcall(function()
  31. data = DataStore:GetAsync(player.UserId.."-dailyReward")
  32. print("Getting Data")
  33. end)
  34.  
  35. if data ~= nil then
  36. -- Returning player to the game
  37.  
  38. local timeSinceLastClaim = timeNow - data -- Number in sec since the last reward was claimed
  39.  
  40. print("Time since last claim "..timeSinceLastClaim)
  41.  
  42. if (timeSinceLastClaim / 3600) >= hourWait then
  43. -- They are eligible for a reward
  44. local reward = possibleRewards[math.random(1,#possibleRewards)]
  45. game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward)
  46. local connection
  47. connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
  48. if triggeringPlayer == player then
  49. print("Reward Claimed")
  50. player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + reward
  51. DataStore:SetAsync(player.UserId.."-dailyReward",os.time())
  52. connection:Disconnect()
  53. end
  54. end)
  55. else
  56. print("Player is uneligible right now")
  57. end
  58.  
  59. else
  60. -- New player
  61. print("New player")
  62.  
  63. local reward = possibleRewards[math.random(1,#possibleRewards)]
  64. game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward)
  65. local connection
  66. connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
  67. if triggeringPlayer == player then
  68. print("Reward Claimed")
  69. player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + reward
  70. DataStore:SetAsync(player.UserId.."-dailyReward",os.time())
  71. connection:Disconnect()
  72. end
  73. end)
  74.  
  75. end
  76.  
  77. local player_data
  78.  
  79.  
  80. pcall(function()
  81. player_data = DataStore:GetAsync(player.UserId.."-Coins")
  82. end)
  83.  
  84. if player_data ~= nil then
  85. -- Player has saved data, load it in
  86. coins.Value = player_data
  87. else
  88. -- New player
  89. coins.Value = defaultCash
  90. end
  91.  
  92. game.Players.PlayerRemoving:Connect(function(player)
  93. pcall(function()
  94. DataStore:SetAsync(player.UserId.."-Coins",player.leaderstats.Coins.Value)
  95. end)
  96.  
  97. print("Saved points")
  98. end)
  99.  
  100. end)
  101.  
  102.  
  103. --[[game.Players.PlayerRemoving:Connect(function(player)
  104. local data
  105. pcall(function()
  106. data = DataStore:GetAsync(player.UserId.."-dailyReward")
  107. print("Getting the Data")
  108. end)
  109.  
  110. if data == nil then
  111. -- New player
  112. pcall(function()
  113. local timeVal = os.time()
  114. DataStore:SetAsync(player.UserId.."-dailyReward")
  115. end)
  116. print("Saved because you are a new player")
  117. end
  118. end)--]]
  119.  
  120. -- Next script; "Points Data Save"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement