Advertisement
Nemeri

Database

Jan 17th, 2022
823
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local ds = game:GetService("DataStoreService")
  2. local plrData = ds:GetDataStore("PlayerData")
  3.  
  4. game.Players.PlayerAdded:Connect(function(plr)
  5.    
  6.     local data = Instance.new('Folder', plr)
  7.     data.Name = 'data'
  8.    
  9.     local nameHere.. = Instance.new('NumberValue', data)
  10.     nameHere.Name = NameHere...
  11.    
  12.     -- load
  13.    
  14.     local plrKey = 'User_'..plr.UserId
  15.    
  16.     local foundedData = plrData:GetAsync(plrKey) -- getting player key
  17.    
  18.     if foundedData then -- if data is founded
  19.    
  20.         for i,v in pairs(data:GetChildren()) do  -- loop on every data
  21.        
  22.             v.Value = foundedData[v.Name]   -- set value to every data
  23.        
  24.         end
  25.        
  26.     end
  27.    
  28. end)
  29.  
  30. game.Players.PlayerRemoving:Connect(function(plr) -- saving data
  31.    
  32.     local plrKey = 'User_'..plr.UserId
  33.    
  34.     local toSave = {}
  35.    
  36.     for i,v in pairs(plr.data:GetChildren()) do
  37.        
  38.         toSave[v.Name] = v.Value
  39.        
  40.     end
  41.    
  42. end)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement