VapeL

DataStore

Sep 27th, 2020 (edited)
967
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --// Setting Up \\--
  2.  
  3. local DataStore2 = require(game:GetService('ServerStorage'):WaitForChild('DataStore2'))
  4.  
  5.  
  6. local starterData = {
  7.     Skill1 = 'One';
  8.     Skill2 = 'Two';
  9.     Skill3 = 'Three';
  10.     Skill4 = 'Four';
  11.     Skill5 = 'Five';
  12.     Skill6 = 'E';
  13.     Skill7 = 'R';
  14.     Skill8 = 'C';
  15.     Skill9 = 'V';
  16.     Sheathe = 'Q';
  17.     Inventory = 'I';
  18.     Settings = 'O';
  19.     Friends = 'U';
  20.     skillTree = 'K';
  21.     Sprint = 'LeftControl';
  22.     Block = 'F';
  23.     Trees = true;
  24.     SunRays = true;
  25. }
  26. -- The first of the DataStore2.Combine is the name of the datastore, the rest are keys.
  27. DataStore2.Combine("settingsDataStore" , "Skill1", "Skill2", "Skill3", "Skill4", "Skill5", "Skill6", "Skill7", "Skill8", "Skill9", "Sheathe", "Inventory", "Settings", "Friends", "skillTree", "Sprint", "Block", "Trees", "Sunrays")
  28.  
  29. --// Functions \\--
  30.  
  31. game:GetService('Players').PlayerAdded:Connect(function(Player)
  32.    
  33.     -- Making a table for the datastores
  34.    
  35.     local dataGet = {
  36.         Skill1 = DataStore2("Skill1", Player);
  37.         Skill2 = DataStore2("Skill2", Player);
  38.         Skill3 = DataStore2("Skill3", Player);
  39.         Skill4 = DataStore2("Skill4", Player);
  40.         Skill5 = DataStore2("Skill5", Player);
  41.         Skill6 = DataStore2("Skill6", Player);
  42.         Skill7 = DataStore2("Skill7", Player);
  43.         Skill8 = DataStore2("Skill8", Player);
  44.         Skill9 = DataStore2("Skill9", Player);
  45.        
  46.         Sheathe = DataStore2("Sheathe", Player);
  47.         Inventory = DataStore2("Inventory", Player);
  48.         Settings = DataStore2("Settings", Player);
  49.         Friends = DataStore2("Friends", Player);
  50.         skillTree = DataStore2("skillTree", Player);
  51.         Sprint = DataStore2("Sprint", Player);
  52.         Block = DataStore2("Block", Player);
  53.        
  54.         Trees = DataStore2("Trees", Player);
  55.         SunRays = DataStore2("Sunrays", Player);
  56.     }
  57.    
  58.     -- Creating player's folders when joined and doing everything else.
  59.    
  60.     local Hotkeys = Instance.new('Folder')
  61.     Hotkeys.Name = "Keybinds"
  62.     Hotkeys.Parent = Player
  63.     local Options = Instance.new('Folder')
  64.     Options.Name = "Options"
  65.     Options.Parent = Player
  66.     local Stats = Instance.new('Folder')
  67.     Stats.Name = "Stats"
  68.     Stats.Parent = Player
  69.     local Inventory = Instance.new('Folder')
  70.     Inventory.Name = "Inventory"
  71.     Inventory.Parent= Player
  72.    
  73.     for i, v in pairs(starterData) do
  74.         if typeof(v) == 'string' then
  75.             local strValue = Instance.new('StringValue')
  76.             strValue.Parent = Hotkeys
  77.             strValue.Name = i
  78.             for i2, v2 in pairs(dataGet) do
  79.                 strValue.Value = v2:Get() or v
  80.                 for i3, v3 in pairs(Hotkeys:GetChildren()) do
  81.                     v3.Changed:Connect(function()
  82.                         i2:Set(i3.Value)
  83.                     end)
  84.                 end
  85.             end
  86.            
  87.         elseif typeof(v) == 'boolean' then
  88.             local boolValue = Instance.new('BoolValue')
  89.             boolValue.Parent = Options
  90.             boolValue.Name = i
  91.             for i2, v2 in pairs(dataGet) do
  92.                 boolValue.Value = v2:Get() or v
  93.                 for i3, v3 in pairs(Options:GetChildren()) do
  94.                     v3.Changed:Connect(function()
  95.                         i2:Set(i3.Value)
  96.                     end)
  97.                 end
  98.             end
  99.            
  100.         elseif typeof(v) == 'number' then
  101.             local intValue = Instance.new('IntValue')
  102.             intValue.Parent = Stats
  103.             intValue.Name = i
  104.             for i2, v2 in pairs(dataGet) do
  105.                 intValue.Value = v2:Get() or v
  106.                 for i3, v3 in pairs(Stats:GetChildren()) do
  107.                     v3.Changed:Connect(function()
  108.                         i2:Set(i3.Value)
  109.                     end)
  110.                 end
  111.             end
  112.         end
  113.     end
  114.    
  115.     print(Player.Name..'\'s data has been created..')
  116. end)
RAW Paste Data