Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.84 KB | None | 0 0
  1. local currencyName = "Money"
  2. local DataStore = game:GetService("DataStoreService"):GetDataStore("LLDSSDS")
  3. game.Players.PlayerAdded:Connect(function(player)
  4.  
  5.     local folder = Instance.new("Folder")
  6.     folder.Name = "leaderstats"
  7.     folder.Parent = player 
  8.    
  9.     local currency = Instance.new("IntValue")
  10.     currency.Name = currencyName
  11.     currency.Parent = folder
  12.    
  13.    
  14.     local ID = currencyName.."-"..player.UserId
  15.     local savedData = nil  
  16.    
  17.     pcall(function()
  18.         savedData = DataStore:GetAsync(ID)
  19.     end)
  20.    
  21.     if savedData ~= nil then
  22.         currency.Value = savedData
  23.         print("Data loaded")
  24.     else
  25.         -- New player
  26.         currency.Value = 100
  27.         print("New player to the game")
  28.     end
  29.    
  30.    
  31. end)
  32.  
  33. game.Players.PlayerRemoving:Connect(function(player)
  34.     local ID = currencyName.."-"..player.UserId
  35.     DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
  36. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement