HowToRoblox

PaycheckSystem

Oct 16th, 2021
791
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local dss = game:GetService("DataStoreService")
  2. local cashDS = dss:GetDataStore("Cash")
  3.  
  4.  
  5. local timePerCheck = 10
  6. local cashPerCheck = 100
  7.  
  8.  
  9. function saveData(p)
  10.    
  11.     pcall(function()
  12.        
  13.         local money = p.leaderstats.Cash.Value
  14.        
  15.         cashDS:SetAsync(p.UserId .. "Cash", money)
  16.     end)
  17. end
  18.  
  19.  
  20. game.Players.PlayerAdded:Connect(function(p)
  21.    
  22.     local leaderstats = Instance.new("Folder", p)
  23.     leaderstats.Name = "leaderstats"
  24.    
  25.     local cash = Instance.new("IntValue", leaderstats)
  26.     cash.Name = "Cash"
  27.    
  28.    
  29.     pcall(function()
  30.        
  31.         local cashData = cashDS:GetAsync(p.UserId .. "Cash") or 0
  32.        
  33.         cash.Value = cashData
  34.     end)
  35.    
  36.    
  37.     while wait(timePerCheck) do
  38.        
  39.         cash.Value += cashPerCheck
  40.        
  41.         game.ReplicatedStorage.PaycheckRE:FireClient(p, cashPerCheck)
  42.     end
  43. end)
  44.  
  45.  
  46. game.Players.PlayerRemoving:Connect(saveData)
  47.  
  48. game:BindToClose(function()
  49.    
  50.     for i, p in pairs(game.Players:GetPlayers()) do
  51.        
  52.         spawn(saveData(p))
  53.     end
  54. end)
RAW Paste Data