Advertisement
AvishalYT

DATA STORE SCRIPT

Aug 27th, 2019
7,169
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. local DataStore = game:GetService("DataStoreService") --// Getting DataStore Service
  2. local Ds1 = DataStore:GetDataStore("[ANY NAME IN HERE]") --// You can name your DataStore Anything :)
  3.  
  4. game.Players.PlayerAdded:Connect(function(player) --// Creates a function when the player is added to the game :)
  5.     local Folder = Instance.new("Folder", player) --// Making a folder that will be stored in the player.
  6.     Folder.Name = "leaderstats" --// Do not change this name.
  7.    
  8.     local Coins = Instance.new("IntValue", Folder) --// A IntValue that is being stored in the leaderstats folder.\
  9.     Coins.Name = "Coins" --// Naming the coins
  10.    
  11.     Coins.Value = Ds1:GetAsync(player.UserId) or 0 --// Getting the data player data
  12.     Ds1:SetAsync(player.UserId, Coins.Value) --// Setting the player Data
  13.    
  14.     Coins.Changed:Connect(function()
  15.         print("Saving Data")
  16.         Ds1:SetAsync(player.UserId, Coins.Value) --// When your coins is changed it will save your data
  17.     end)
  18. end)
  19.  
  20.  
  21. game.Players.PlayerRemoving:Connect(function(player)
  22.     print("Player Has Left")
  23.     Ds1:SetAsync(player.UserId, player.leaderstats.Coins.Value)
  24. end)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement