Advertisement
Guest User

eh

a guest
Nov 11th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. local ds = require(script.Parent.DataStore2)
  2.  
  3.  
  4. ds.Combine('MasterKey','Pancakes','Coins','Rubies')
  5.  
  6. local DefaultPancakes = 0
  7. local DefaultCoins = 0
  8. local DefaultRubies = 0
  9.  
  10. game.Players.PlayerAdded:connect(function(Player)
  11.  
  12. -- Creating Leaderstats
  13.  
  14. local stats = Instance.new('Folder',Player)
  15. stats.Name = 'leaderstats'
  16.  
  17. local Pancakes = Instance.new('IntValue',stats);Pancakes.Name = 'Pancakes'
  18. local Coins = Instance.new('IntValue',stats);Coins.Name = 'Coins'
  19. local Rubies = Instance.new('IntValue',stats);Rubies.Name = 'Rubies'
  20.  
  21. -- Getting Leaderstats Datastore
  22.  
  23. local PStore = ds('Pancakes',Player)
  24. local CStore = ds('Coins',Player)
  25. local RStore = ds('Rubies',Player)
  26.  
  27. -- Functions for updating leaderstats in-game
  28.  
  29. local function SetPancakes(val)
  30. Pancakes.Value = val
  31. end
  32. local function SetCoins(val)
  33. Coins.Value = val
  34. end
  35. local function SetRubies(val)
  36. Rubies.Value = val
  37. end
  38.  
  39. -- Setting in-game leaderstats to datastore values
  40.  
  41. SetPancakes(PStore:Get(DefaultPancakes))
  42. SetCoins(CStore:Get(DefaultCoins))
  43. SetRubies(RStore:Get(DefaultRubies))
  44.  
  45. -- Updating in-game leaderstats on Datastore update
  46.  
  47. PStore:OnUpdate(SetPancakes)
  48. CStore:OnUpdate(SetCoins)
  49. RStore:OnUpdate(SetRubies)
  50.  
  51. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement