Sungmingamerpro13

Main Game's Pet DataStoreService (STORY GAME)

Jun 26th, 2026 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 0.93 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 EquippedPet = Instance.new("StringValue")
  14.     EquippedPet.Name = "EquippedPet"
  15.     EquippedPet.Parent = Player
  16.  
  17.     local Success, Data = pcall(function()
  18.         return PetStore:GetAsync(Player.UserId)
  19.     end)
  20.  
  21.     if Success and Data then
  22.  
  23.         Coins.Value = Data.Coins or numberValue
  24.         EquippedPet.Value = Data.EquippedPet or ""
  25.  
  26.     else
  27.  
  28.         Coins.Value = numberValue
  29.  
  30.     end
  31.  
  32. end)
  33.  
  34. game.Players.PlayerRemoving:Connect(function(Player)
  35.  
  36.     pcall(function()
  37.  
  38.         PetStore:SetAsync(Player.UserId,{
  39.             Coins = Player.Coins.Value,
  40.             EquippedPet = Player.EquippedPet.Value
  41.         })
  42.  
  43.     end)
  44.  
  45. end)
  46.  
Advertisement
Add Comment
Please, Sign In to add comment