Guest User

Untitled

a guest
Apr 7th, 2020
189
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local dataStoreService = game:GetService("DataStoreService")
  2. local statStore = dataStoreService:GetDataStore("Test4242")
  3. local accessories = {}
  4. local Data = game.ReplicatedStorage.Data
  5. local Folder = Data:Clone()
  6.  
  7. local function AttachToBack(Player, Object, Offset)
  8.     if not Offset then Offset = Vector3.new(0, 0, 0) end
  9.     Object = Object:Clone()
  10.     local Character = Player.Character or Player.CharacterAdded:Wait()
  11.     local CharacterTorso = Character:FindFirstChild("Torso") or Character:FindFirstChild("UpperTorso")
  12.          
  13.     Object.Parent = Character
  14.     Object:SetPrimaryPartCFrame(CharacterTorso.CFrame * CFrame.new(Offset))
  15.          
  16.     local Weld = Instance.new("WeldConstraint")
  17.     Weld.Parent = Object
  18.     Weld.Part0 = CharacterTorso
  19.     Weld.Part1 = Object.PrimaryPart
  20. end
  21.  
  22. local function AttachToBack2(Player, Object, Offset)
  23.     if not Offset then Offset = Vector3.new(0, 0, 0) end
  24.     Object = Object:Clone()
  25.     local Character = Player.Character or Player.CharacterAdded:Wait()
  26.     local CharacterTorso = Character:FindFirstChild("Head")
  27.          
  28.     Object.Parent = Character.Helmets
  29.     Object:SetPrimaryPartCFrame(CharacterTorso.CFrame * CFrame.new(Offset))
  30.          
  31.     local Weld = Instance.new("WeldConstraint")
  32.     Weld.Parent = Object
  33.     Weld.Part0 = CharacterTorso
  34.     Weld.Part1 = Object.PrimaryPart
  35. end
  36.  
  37. game.Players.PlayerAdded:Connect(function(player)
  38.     Folder.Parent = player
  39.     local leaderstats = player:WaitForChild("Data")
  40.     local money = leaderstats:WaitForChild("Shirt")
  41.     local backpack = leaderstats:WaitForChild("HasBackpack")
  42.     local Hat = leaderstats:WaitForChild("HasHat")
  43.     local tix = leaderstats:WaitForChild("Pants")
  44.    
  45.     local char = player.Character or player.CharacterAdded:Wait()
  46.    
  47.     local recieved, notRecieved = pcall(function()
  48.         stat = statStore:GetAsync("UserId-"..player.UserId)
  49.     end)
  50.    
  51.     if recieved then
  52.         local Hat = player.Data.HasHat
  53.         money.ShirtTemplate = stat[1]
  54.         tix.PantsTemplate = stat[2]
  55.         backpack.Value = stat[3]
  56.         Hat.Value = stat[4]
  57.         print("Data was recieved")
  58.     else
  59.         print("Data was not recieved")
  60.     end
  61.    
  62.     for _, accessory in pairs(player.Character.Humanoid:GetAccessories()) do
  63.         table.insert(accessories, accessory:Clone())
  64.         end
  65.    
  66.     if stat [3] == true then
  67.         wait(5)
  68.         AttachToBack(player, game.ReplicatedStorage.BackpackModel, Vector3.new(0, 0.5, 0.7))
  69.     end
  70.    
  71.     if stat [4] == "Marine" then
  72.         wait(5)
  73.         player.Character.Humanoid:RemoveAccessories()
  74.         AttachToBack2(player, game.ReplicatedStorage.MarineHelmet, Vector3.new(0.04, 0.05, -0.01))
  75.         elseif stat [4] == "Army" then
  76.         wait(5)
  77.         player.Character.Humanoid:RemoveAccessories()
  78.         AttachToBack2(player, game.ReplicatedStorage.ArmyHelmet, Vector3.new(0.04, 0.05, -0.01))
  79.     end
  80.    
  81.     backpack.Changed:Connect(function()
  82.     local backpack = player.Data.HasBackpack
  83.         local Hat = player.Data.HasHat
  84.         statStore:SetAsync("UserId-"..player.UserId,{money.ShirtTemplate, tix.PantsTemplate, backpack.Value, Hat.Value})
  85.         char.Shirt.ShirtTemplate = money.ShirtTemplate
  86.         char.Pants.PantsTemplate = tix.PantsTemplate
  87.         print("Data was saved!")
  88.     end)
  89.        
  90.     Hat.Changed:Connect(function()
  91.     local backpack = player.Data.HasBackpack
  92.         local Hat = player.Data.HasHat
  93.         statStore:SetAsync("UserId-"..player.UserId,{money.ShirtTemplate, tix.PantsTemplate, backpack.Value, Hat.Value})
  94.         char.Shirt.ShirtTemplate = money.ShirtTemplate
  95.         char.Pants.PantsTemplate = tix.PantsTemplate
  96.         print("Data was saved!")
  97.     end)
  98.        
  99.     tix.Changed:Connect(function()
  100.         local backpack = player.Data.HasBackpack
  101.         local Hat = player.Data.HasHat
  102.         statStore:SetAsync("UserId-"..player.UserId,{money.ShirtTemplate, tix.PantsTemplate, backpack.Value, Hat.Value})
  103.         char.Shirt.ShirtTemplate = money.ShirtTemplate
  104.         char.Pants.PantsTemplate = tix.PantsTemplate
  105.         print("Data was saved!")
  106.         end)
  107.  
  108. game.Players.PlayerRemoving:Connect(function(player)
  109.     local leaderstats = player:WaitForChild("Data")
  110.     local money = leaderstats:WaitForChild("Shirt")
  111.     local backpack = leaderstats:WaitForChild("HasBackpack")
  112.     local Hat = leaderstats:WaitForChild("HasHat")
  113.     local tix = leaderstats:WaitForChild("Pants")
  114.    
  115.     local saved, notSaved = pcall(function()
  116.         statStore:SetAsync("UserId-"..player.UserId,{money.ShirtTemplate,tix.PantsTemplate, backpack.Value, Hat.Value})
  117.     end)
  118.    
  119.     if saved then
  120.         print("Data was saved")
  121.     else
  122.         print("Data was not saved")
  123.     end
  124.     end)
  125. end)
RAW Paste Data