Sungmingamerpro13

Lobby's Pet DataStoreService (STORY GAME)

Jun 14th, 2026 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.38 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local DataStoreService = game:GetService("DataStoreService")
  3. local PetStore = DataStoreService:GetDataStore("PetData")
  4.  
  5. local numberValue = 0
  6.  
  7. game.Players.PlayerAdded:Connect(function(Player)
  8.  
  9.     local Coins = Instance.new("NumberValue")
  10.     Coins.Name = "Coins"
  11.     Coins.Parent = Player
  12.  
  13.     local OwnedPets = Instance.new("Folder")
  14.     OwnedPets.Name = "OwnedPets"
  15.     OwnedPets.Parent = Player
  16.  
  17.     local EquippedPet = Instance.new("StringValue")
  18.     EquippedPet.Name = "EquippedPet"
  19.     EquippedPet.Parent = Player
  20.  
  21.     local Success, Data = pcall(function()
  22.         return PetStore:GetAsync(Player.UserId)
  23.     end)
  24.  
  25.     if Success and Data then
  26.  
  27.         Coins.Value = Data.Coins or numberValue
  28.         EquippedPet.Value = Data.EquippedPet or ""
  29.  
  30.         if Data.OwnedPets then
  31.             for PetName, HasPet in pairs(Data.OwnedPets) do
  32.  
  33.                 if HasPet then
  34.                     local Pet = Instance.new("BoolValue")
  35.                     Pet.Name = PetName
  36.                     Pet.Parent = OwnedPets
  37.                 end
  38.  
  39.             end
  40.         end
  41.  
  42.     else
  43.         Coins.Value = numberValue
  44.     end
  45.  
  46. end)
  47.  
  48. game.Players.PlayerRemoving:Connect(function(Player)
  49.  
  50.     local Pets = {}
  51.  
  52.     for _, Pet in ipairs(Player.OwnedPets:GetChildren()) do
  53.         Pets[Pet.Name] = true
  54.     end
  55.  
  56.     pcall(function()
  57.  
  58.         PetStore:SetAsync(Player.UserId,{
  59.             Coins = Player.Coins.Value,
  60.             OwnedPets = Pets,
  61.             EquippedPet = Player.EquippedPet.Value
  62.         })
  63.  
  64.     end)
  65.  
  66. end)
  67.  
Advertisement
Add Comment
Please, Sign In to add comment