Advertisement
SourceYT

SaveData Script

Jul 13th, 2020
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. -- Script might not work, my guess is because I didn't use remote events, if that is the case, hit me up in the comments
  2. -- I will go ahead and make a video on how to use remote events along with fixing this script or just a brand new script
  3. -- Source
  4.  
  5. local DS = game:GetService("DataStoreService"):GetDataStore("ScriptingTuts_01") -- Changing "ScriptingTuts_01" will make a new SaveData
  6. game.Players.PlayerAdded:Connect(function(plr)
  7.     wait()
  8.     local plrkey = "id_"..plr.userId
  9.    
  10.     local savevalue = plr.leaderstats.Points -- Change to your actual value
  11.  
  12.     local GetSaved = DS:GetAsync(plrkey)
  13.     if GetSaved then
  14.         savevalue.Value = GetSaved[1] -- Check video to see how to include more than 1 value
  15.     else
  16.         local NumbersForSaving = {savevalue.Value}
  17.         DS:GetAsync(plrkey, NumbersForSaving)
  18.     end
  19. end)
  20.  
  21. game.Players.PlayerRemoving:Connect(function(plr)
  22.     DS:SetAsync("id_"..plr.userId, {plr.leaderstats.Points.Value}) -- Check video to see how to include more than 1 value
  23.     warn("Saved Points") -- you can delete this line if you want to
  24. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement