Advertisement
Joriangames

Saving Cash script

Dec 26th, 2020
3,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. --Thanks for using this script
  2. --This script is made by Joriangames/Problox Studio Scripts
  3. --Want to know how to use this? Watch my tutorial: https://youtu.be/4paRumpzt0g
  4.  
  5.  
  6. local DSS = game:GetService("DataStoreService")
  7. local myDataStore = DSS:GetDataStore("myDataStore")
  8.  
  9. game.Players.PlayerAdded:Connect(function(plr)
  10.     local lead = Instance.new("Folder")
  11.     lead.Name = "leaderstats"
  12.     lead.Parent = plr
  13.    
  14.     local Cash = Instance.new("IntValue")
  15.     Cash.Name = "Cash"
  16.     Cash.Parent = lead
  17.    
  18.     local data
  19.     local succ, err = pcall(function()
  20.         data = myDataStore:GetAsync(plr.UserId.."_cash", plr.leaderstats.Cash.Value)
  21.     end)   
  22.    
  23.     if succ then
  24.         Cash.Value = data      
  25.         --set the data equal to the current cash
  26.         print("Succesfully got the data!")
  27.     end
  28. end)
  29.  
  30.  
  31. game.Players.PlayerRemoving:Connect(function(plr)
  32.    
  33.     local data = plr.leaderstats.Cash.Value
  34.    
  35.     local succ, err = pcall(function()
  36.         myDataStore:SetAsync(plr.UserId.."_cash", plr.leaderstats.Cash.Value)
  37.     end)
  38.    
  39.     if succ then
  40.         print("Succesfully saved the data!")
  41.     else
  42.         print("There was an error while saving data")
  43.         warn(err)
  44.     end
  45. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement