Advertisement
HowToRoblox

RewardHandler

Dec 12th, 2021 (edited)
2,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. local groupID = 2929563
  2.  
  3. local dss = game:GetService("DataStoreService")
  4. local rewardsDS = dss:GetDataStore("GroupRewards")
  5.  
  6.  
  7. function saveData(plr)
  8.  
  9.     rewardsDS:SetAsync(plr.UserId .. "Cash", plr.leaderstats.Cash.Value)
  10. end
  11.  
  12.  
  13. game.Players.PlayerAdded:Connect(function(plr)
  14.  
  15.     local ls = Instance.new("Folder")
  16.     ls.Name = "leaderstats"
  17.     ls.Parent = plr
  18.  
  19.     local cash = Instance.new("IntValue")
  20.     cash.Name = "Cash"
  21.     cash.Parent = ls
  22.  
  23.  
  24.     local cashData = rewardsDS:GetAsync(plr.UserId .. "Cash") or 0
  25.     local hasClaimed = rewardsDS:GetAsync(plr.UserId .. "Claimed")
  26.  
  27.     cash.Value = cashData
  28.  
  29.  
  30.     if plr:IsInGroup(groupID) and not hasClaimed then
  31.  
  32.         rewardsDS:SetAsync(plr.UserId .. "Claimed", true)
  33.  
  34.         cash.Value += 100
  35.     end
  36. end)
  37.  
  38.  
  39. game.Players.PlayerRemoving:Connect(saveData)
  40.  
  41. game:BindToClose(function()
  42.  
  43.     for i, plr in pairs(game.Players:GetPlayers()) do
  44.  
  45.         saveData(plr)
  46.     end
  47. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement