Sungmingamerpro13

BuyScript for Story Games

Jun 14th, 2026 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 0.83 KB | None | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2.  
  3. local BuyPet = ReplicatedStorage:WaitForChild("BuyPet")
  4.  
  5. BuyPet.OnServerEvent:Connect(function(Player, PetName)
  6.  
  7.     local Pet = ReplicatedStorage.petsFolder:FindFirstChild(PetName)
  8.  
  9.     if not Pet then
  10.         return
  11.     end
  12.  
  13.     local OwnedPets = Player:FindFirstChild("OwnedPets")
  14.  
  15.     if not OwnedPets then
  16.         OwnedPets = Instance.new("Folder")
  17.         OwnedPets.Name = "OwnedPets"
  18.         OwnedPets.Parent = Player
  19.     end
  20.  
  21.     -- Ya la tiene comprada
  22.     if OwnedPets:FindFirstChild(PetName) then
  23.         return
  24.     end
  25.  
  26.     local Coins = Player:FindFirstChild("Coins")
  27.     if not Coins then return end
  28.  
  29.     local Price = Pet.Price.Value
  30.  
  31.     if Coins.Value >= Price then
  32.  
  33.         Coins.Value -= Price
  34.  
  35.         local Value = Instance.new("BoolValue")
  36.         Value.Name = PetName
  37.         Value.Parent = OwnedPets
  38.  
  39.     end
  40. end)
  41.  
Advertisement
Add Comment
Please, Sign In to add comment