Advertisement
supborzuki

Scripts For Data Store!

May 29th, 2021
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. -- Leaderstats
  2.  
  3. game.Players.PlayerAdded:Connect(function(player)
  4. local s = Instance.new("Folder",player)
  5. s.Name = "leaderstats"
  6.  
  7. local strength = Instance.new("IntValue",s)
  8. strength.Name = "Strength" -- You stat name
  9.  
  10.  
  11. end)
  12.  
  13. -- Data Store
  14.  
  15. local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
  16. game.Players.PlayerAdded:Connect(function(plr)
  17. wait()
  18. local plrkey = "id_"..plr.userId
  19. local save1 = plr.leaderstats.Strength -- You Stat name
  20.  
  21. local GetSaved = ds:GetAsync(plrkey)
  22. if GetSaved then
  23. save1.Value = GetSaved[1]
  24. else
  25. local NFS = {save1.Value}
  26. ds:GetAsync(plrkey, NFS)
  27. end
  28. end)
  29.  
  30. game.Players.PlayerRemoving:Connect(function(plr)
  31. ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Strength.Value}) -- Your stat name --
  32. end)
  33.  
  34. -- localscript in gui
  35.  
  36. script.Parent.MouseButton1Click:Connect(function()
  37. workspace.AddStrength.Add1:FireServer()
  38. script.Parent.Active = false
  39. wait()
  40. script.Parent.Active = true
  41. end)
  42.  
  43. -- Events Script
  44. script.Add1.OnServerEvent:Connect(function(player)
  45. player.leaderstats.Strength.Value = player.leaderstats.Strength.Value +1
  46. end)
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement