qsenko1

PetshopValueSave

Aug 3rd, 2021
675
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local DataStoreService = game:GetService("DataStoreService")
  2. local Petsdata = DataStoreService:GetDataStore("PetShop2")
  3.  
  4. game.Players.PlayerAdded:Connect(function(player)
  5.     --Pets stuff
  6.     local PetsFolder = Instance.new("Folder",player); PetsFolder.Name = "PetsFolder"
  7.     local Pets = Instance.new("Folder",PetsFolder); Pets.Name = "Pets"
  8.     local PetsValues = Instance.new("Folder",PetsFolder); PetsValues.Name = "Values"
  9.     local PetNameCheck = Instance.new("StringValue",PetsFolder); PetNameCheck.Name = "PetNameCheck"
  10.     --Pets Values
  11.     local Turtle = Instance.new("BoolValue",PetsValues); Turtle.Name = "Turtle"
  12.     local Bunny = Instance.new("BoolValue",PetsValues); Bunny.Name = "Bunny"
  13.     local Parrot = Instance.new("BoolValue",PetsValues); Parrot.Name = "Parrot"
  14.     local PiggyBank = Instance.new("BoolValue",PetsValues); PiggyBank.Name = "Piggy Bank"
  15.     local MrCrab = Instance.new("BoolValue",PetsValues); MrCrab.Name = "Mr.Crab"
  16.     local PufferFish = Instance.new("BoolValue",PetsValues); PufferFish.Name = "Puffer Fish"
  17.     local Hedgehog = Instance.new("BoolValue",PetsValues); Hedgehog.Name = "Hedgehog"
  18.     local CrocodilePal = Instance.new("BoolValue",PetsValues); CrocodilePal.Name = "CrocodilePal"
  19.     local KingFrog = Instance.new("BoolValue",PetsValues); KingFrog.Name = "King Frog"
  20.     local Kitty = Instance.new("BoolValue",PetsValues); Kitty.Name = "Kitty"
  21.     local EpicDuck = Instance.new("BoolValue",PetsValues); EpicDuck.Name = "Epic Duck"
  22.     local Octopus = Instance.new("BoolValue",PetsValues); Octopus.Name = "Octopus"
  23.     local PetRock = Instance.new("BoolValue",PetsValues); PetRock.Name = "Pet Rock"
  24.     local SeaMonster = Instance.new("BoolValue",PetsValues); SeaMonster.Name = "Sea Monster"
  25.     local Pikachu = Instance.new("BoolValue",PetsValues); Pikachu.Name = "Pikachu"
  26.     local OOFSpider = Instance.new("BoolValue",PetsValues); OOFSpider.Name = "OOF Spider"
  27.     local PetGojira = Instance.new("BoolValue",PetsValues); PetGojira.Name = "Pet Gojira"
  28.     local Scorpion = Instance.new("BoolValue",PetsValues); Scorpion.Name = "Scorpion"
  29.     local HungryShark = Instance.new("BoolValue",PetsValues); HungryShark.Name = "Hungry Shark"
  30.     local AnnoyingOrange = Instance.new("BoolValue",PetsValues); AnnoyingOrange.Name = "Annoying Orange"
  31.     local EvilUnicorn = Instance.new("BoolValue",PetsValues); EvilUnicorn.Name = "Evil Unicorn"
  32.     local ArcticReindeer = Instance.new("BoolValue",PetsValues); ArcticReindeer.Name = "Arctic Reindeer"
  33.     local Bird = Instance.new("BoolValue",PetsValues); Bird.Name = "Bird"
  34.     local GrayWolf = Instance.new("BoolValue",PetsValues); GrayWolf.Name = "Gray Wolf"
  35.     local Dog = Instance.new("BoolValue",PetsValues); Dog.Name = "Dog"
  36.     local Otter = Instance.new("BoolValue",PetsValues); Otter.Name = "Otter"
  37.     local AlienBee = Instance.new("BoolValue",PetsValues); AlienBee.Name = "Alien Bee"
  38.     local TRex = Instance.new("BoolValue",PetsValues); TRex.Name = "T-Rex"
  39.     local Phoenix = Instance.new("BoolValue",PetsValues); Phoenix.Name = "Phoenix"
  40.     local HellDragon = Instance.new("BoolValue",PetsValues); HellDragon.Name = "Hell Dragon"
  41.     --Hidden Pet Value
  42.     local HiddenPetValue = Instance.new("BoolValue",PetsValues); HiddenPetValue.Name = "Eye of Cthulhu"
  43.    
  44.     local Player = "Player_"..player.UserId
  45.  
  46.     --Load Data
  47.     local data
  48.     local success, errormessage = pcall(function()
  49.         data = Petsdata:GetAsync(Player) --.UserId
  50.     end)
  51.  
  52.     if success then
  53.         if data then
  54.             PetNameCheck.Value = data.PetNameCheck;
  55.             Turtle.Value = data.Turtle;
  56.             Bunny.Value = data.Bunny;
  57.             Parrot.Value = data.Parrot;
  58.             PiggyBank.Value = data.PiggyBank;
  59.             MrCrab.Value = data.MrCrab;
  60.             PufferFish.Value = data.PufferFish;
  61.             Hedgehog.Value = data.Hedgehog;
  62.             CrocodilePal.Value = data.CrocodilePal;
  63.             KingFrog.Value = data.KingFrog;
  64.             Kitty.Value = data.Kitty;
  65.             EpicDuck.Value = data.EpicDuck;
  66.             Octopus.Value = data.Octopus;
  67.             PetRock.Value = data.PetRock;
  68.             SeaMonster.Value = data.SeaMonster;
  69.             Pikachu.Value = data.Pikachu;
  70.             OOFSpider.Value = data.OOFSpider;
  71.             PetGojira.Value = data.PetGojira;
  72.             Scorpion.Value = data.Scorpion;
  73.             HungryShark.Value = data.HungryShark;
  74.             AnnoyingOrange.Value = data.AnnoyingOrange;
  75.             EvilUnicorn.Value = data.EvilUnicorn;
  76.             ArcticReindeer.Value = data.ArcticReindeer;
  77.             Bird.Value = data.Bird;
  78.             GrayWolf.Value = data.GrayWolf;
  79.             Dog.Value = data.Dog;
  80.             Otter.Value = data.Otter;
  81.             AlienBee.Value = data.AlienBee;
  82.             TRex.Value = data.TRex;
  83.             Phoenix.Value = data.Phoenix;
  84.             HellDragon.Value = data.HellDragon;
  85.             HiddenPetValue.Value = data.HiddenPetValue;
  86.         end        
  87.     end    
  88.    
  89.     if player.Character then
  90.         local Pets = game:GetService("ReplicatedStorage").Pets.ActualPets:GetChildren()
  91.         for i,pets in pairs(Pets) do       
  92.             if pets:IsA("Model") then
  93.                 if player.PetsFolder:FindFirstChild("PetNameCheck").Value == pets.Name then
  94.                     local pet = pets:Clone()
  95.                     pet.Parent = player.Character
  96.                     break
  97.                 end
  98.             end
  99.         end
  100.     end
  101.  
  102. game.Players.PlayerRemoving:Connect(function(player)
  103.    
  104.     local Player = "Player_"..player.UserId
  105.    
  106.     local data = {
  107.         Turtle = player.PetsFolder.Values.Turtle.Value;
  108.         Bunny = player.PetsFolder.Values.Bunny.Value;
  109.         Parrot = player.PetsFolder.Values.Parrot.Value;
  110.         PiggyBank = player.PetsFolder.Values["Piggy Bank"].Value;
  111.         MrCrab = player.PetsFolder.Values["Mr.Crab"].Value;
  112.         PufferFish = player.PetsFolder.Values["Puffer Fish"].Value;
  113.         Hedgehog = player.PetsFolder.Values.Hedgehog.Value;
  114.         CrocodilePal = player.PetsFolder.Values.CrocodilePal.Value;
  115.         KingFrog = player.PetsFolder.Values["King Frog"].Value;
  116.         Kitty = player.PetsFolder.Values.Kitty.Value;
  117.         EpicDuck = player.PetsFolder.Values["Epic Duck"].Value;
  118.         Octopus = player.PetsFolder.Values.Octopus.Value;
  119.         PetRock = player.PetsFolder.Values["Pet Rock"].Value;
  120.         SeaMonster = player.PetsFolder.Values["Sea Monster"].Value;
  121.         Pikachu = player.PetsFolder.Values.Pikachu.Value;
  122.         OOFSpider = player.PetsFolder.Values["OOF Spider"].Value;
  123.         PetGojira = player.PetsFolder.Values["Pet Gojira"].Value;
  124.         Scorpion = player.PetsFolder.Values.Scorpion.Value;
  125.         HungryShark = player.PetsFolder.Values["Hungry Shark"].Value;
  126.         AnnoyingOrange = player.PetsFolder.Values["Annoying Orange"].Value;
  127.         EvilUnicorn = player.PetsFolder.Values["Evil Unicorn"].Value;
  128.         ArcticReindeer = player.PetsFolder.Values["Arctic Reindeer"].Value;
  129.         Bird = player.PetsFolder.Values.Bird.Value;
  130.         GrayWolf = player.PetsFolder.Values["Gray Wolf"].Value;
  131.         Dog = player.PetsFolder.Values.Dog.Value;
  132.         Otter = player.PetsFolder.Values.Otter.Value;
  133.         AlienBee = player.PetsFolder.Values["Alien Bee"].Value;
  134.         TRex = player.PetsFolder.Values["T-Rex"].Value;
  135.         Phoenix = player.PetsFolder.Values.Phoenix.Value;
  136.         HellDragon = player.PetsFolder.Values["Hell Dragon"].Value;
  137.         HiddenPetValue = player.PetsFolder.Values["Eye of Cthulhu"].Value;
  138.         PetNameCheck = player.PetsFolder.PetNameCheck.Value;
  139.     };
  140.  
  141.     local success, errormessage = pcall(function()
  142.         Petsdata:SetAsync(Player, data)
  143.     end)
  144.  
  145.     if success then
  146.         print("Pets successfully saved:)")
  147.     else
  148.         print("There was an error!")
  149.         warn(errormessage)
  150.     end
  151.    
  152. end)
RAW Paste Data