HowToRoblox

PetGuiHandler

Sep 25th, 2021
1,101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local re = game.ReplicatedStorage:WaitForChild("PetSystemRE")
  2.  
  3. local hatched = script.Parent.PetHatchedFrame
  4. local inv = script.Parent.PetInventoryFrame
  5. hatched.Visible, inv.Visible = false, false
  6.  
  7.  
  8. local ownedPets = game.Players.LocalPlayer:WaitForChild("OwnedPets")
  9.  
  10.  
  11. local rarityOrder = {"Common", "Uncommon", "Rare", "Special"}
  12.  
  13.  
  14. function updateInventory()
  15.    
  16.     for i, child in pairs(inv.PetScroller:GetChildren()) do
  17.        
  18.         if child:IsA("ImageButton") then child:Destroy() end
  19.     end
  20.    
  21.     local pets = ownedPets:GetChildren()
  22.    
  23.     table.sort(pets, function(a, b)
  24.            
  25.         local rarityA = 1
  26.         local rarityB = 1
  27.            
  28.         for i, descendant in pairs(game.ReplicatedStorage:WaitForChild("Pets"):GetDescendants()) do
  29.                
  30.             if descendant.Name == a.Name then
  31.                 rarityA = table.find(rarityOrder, descendant.Parent.Name)
  32.                    
  33.             elseif descendant.Name == b.Name then
  34.                 rarityB = table.find(rarityOrder, descendant.Parent.Name)
  35.             end
  36.         end
  37.        
  38.         return rarityA > rarityB
  39.     end)
  40.    
  41.    
  42.     for i, pet in pairs(pets) do
  43.        
  44.         local newButton = script.PetButton:Clone()
  45.        
  46.         newButton.PetName.Text = pet.Name
  47.        
  48.         for x, descendant in pairs(game.ReplicatedStorage:WaitForChild("Pets"):GetDescendants()) do
  49.             if descendant.Name == pet.Name then
  50.                 newButton.PetRarity.Text = descendant.Parent.Name
  51.             end
  52.         end
  53.        
  54.         local cam = Instance.new("Camera", newButton.PetImage)
  55.         newButton.PetImage.CurrentCamera = cam
  56.  
  57.         local vpfPet = pet:Clone()
  58.         vpfPet.Parent = newButton.PetImage
  59.  
  60.         cam.CFrame = CFrame.new(vpfPet.Position + vpfPet.CFrame.LookVector * 3 + Vector3.new(0, -1, -1), vpfPet.Position)
  61.        
  62.         newButton.Parent = inv.PetScroller
  63.        
  64.         inv.PetScroller.CanvasSize = UDim2.new(0, 0, 0, inv.PetScroller.UIGridLayout.AbsoluteContentSize.Y)
  65.        
  66.        
  67.         newButton.MouseButton1Click:Connect(function()
  68.            
  69.             re:FireServer(pet)
  70.         end)
  71.     end
  72. end
  73.  
  74.  
  75. script.Parent.InventoryButton.MouseButton1Click:Connect(function()
  76.    
  77.     inv.Visible = not inv.Visible
  78. end)
  79.  
  80. inv.CloseButton.MouseButton1Click:Connect(function()
  81.    
  82.     inv.Visible = not inv.Visible
  83. end)
  84.  
  85.  
  86. updateInventory()
  87.  
  88. ownedPets.DescendantAdded:Connect(updateInventory)
  89. ownedPets.DescendantRemoving:Connect(updateInventory)
  90.  
  91.  
  92.  
  93. re.OnClientEvent:Connect(function(pet)
  94.    
  95.     hatched.PetImage:ClearAllChildren()
  96.    
  97.     local cam = Instance.new("Camera", hatched.PetImage)
  98.     hatched.PetImage.CurrentCamera = cam
  99.    
  100.     local vpfPet = pet:Clone()
  101.     vpfPet.Parent = hatched.PetImage
  102.    
  103.     cam.CFrame = CFrame.new(vpfPet.Position + vpfPet.CFrame.LookVector * 3 + Vector3.new(0, -1, -1), vpfPet.Position)
  104.    
  105.    
  106.     hatched.PetName.Text = pet.Name
  107.    
  108.     for x, descendant in pairs(game.ReplicatedStorage:WaitForChild("Pets"):GetDescendants()) do
  109.         if descendant.Name == pet.Name then
  110.             hatched.PetRarity.Text = descendant.Parent.Name
  111.         end
  112.     end
  113.    
  114.    
  115.     hatched.Visible = true
  116.    
  117.     hatched.ClaimButton.MouseButton1Click:Wait()
  118.    
  119.     hatched.Visible = false
  120. end)
RAW Paste Data