SHARE
TWEET

Untitled

a guest Mar 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local TS = game:GetService("TweenService")
  2. local RS = game:GetService("ReplicatedStorage")
  3. local Library = RS:WaitForChild("PetLibrary")
  4. local Eggs = require(Library:WaitForChild("Config"))
  5. local Data = Eggs[script.Parent.Name]
  6. local Cost = Data["Cost"]
  7. local Pets = Data["Pets"]
  8.  
  9. local Buy = script.Parent:WaitForChild("Buy")
  10. local CD = Buy:WaitForChild("ClickDetector")
  11. local CostGUI = Buy:WaitForChild("Cost")
  12. local CostText = CostGUI:WaitForChild("TextLabel")
  13.  
  14. local NamePlate = script.Parent:WaitForChild("NamePlate")
  15. local NameGUI = NamePlate:WaitForChild("Name")
  16. local NameText = NameGUI:WaitForChild("TextLabel")
  17.  
  18. local Egg = script.Parent:WaitForChild("Egg")
  19.  
  20. CostText.Text = "Cost: "..Cost.." PizzaCoins"
  21. NameText.Text = script.Parent.Name.." Egg"
  22.  
  23. local function RotateTween(Obj, Rot)
  24.     local TI = TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
  25.     local properties = {
  26.         Rotation = Rot
  27.     }
  28. local Tween = TS:Create(Obj, TI, properties)
  29. Tween:Play()
  30. end
  31.  
  32.  
  33. local TotalWeight = 0
  34. for i,v in pairs(Pets) do
  35.     TotalWeight = TotalWeight + v[1]
  36. end
  37.  
  38. local function ChoosePet()
  39.     local Chance = math.random(1,TotalWeight)
  40.     local Counter = 0
  41.     for i,v in pairs(Pets) do
  42.         Counter = Counter+v[1]
  43.         if Chance <= Counter then
  44.             return i
  45.         end
  46.     end
  47. end
  48.  
  49. local function UnboxPet(Player)
  50.     local PetInv = Player:WaitForChild("Pets")
  51.     local PetChosen = ChoosePet()
  52.     Library:WaitForChild(PetChosen):Clone().Parent = PetInv
  53.     print(Player.Name.." Hatched a "..PetChosen)
  54.     local Gui = Instance.new("ScreenGui")
  55.     local viewport = Instance.new("ViewportFrame")
  56.     viewport.Size = UDim2.new(1, 0, 1, 0)
  57.     viewport.BackgroundTransparency = 1
  58.     local EggClone = Egg:Clone()
  59.     local Pos = EggClone.PrimaryPart.Position
  60.     EggClone.Parent = viewport
  61.     local Camera = Instance.new("Camera")
  62.     Camera.Parent = viewport
  63.     viewport.CurrentCamera = Camera
  64.     viewport.Parent = Gui
  65.     Camera.CFrame = CFrame.new(Vector3.new(Pos.X, Pos.Y, Pos.Z+5),Pos)
  66.     Gui.Parent = Player.PlayerGui
  67.     wait(1)
  68.     for i = 1,5 do
  69.         RotateTween(viewport,25)
  70.         wait(.1)
  71.         RotateTween(viewport,-25)
  72.         wait(.1)
  73.     end
  74.     RotateTween(viewport,0)
  75.     wait(.5)
  76.     EggClone:Destroy()
  77.     local PetClone = Library:WaitForChild(PetChosen):Clone()
  78.     local HeadPos = PetClone.PrimaryPart.Position
  79.     PetClone.Parent = viewport
  80.     Camera.CFrame = CFrame.new(Vector3.new(HeadPos.X,HeadPos.Y,HeadPos.Z+10),HeadPos)
  81.     wait(1)
  82.     Gui:Destroy()
  83. end
  84. local Cool = false
  85. game.ReplicatedStorage.Eggs.BuyUnCommon.OnServerEvent:Connect(function(Player)
  86.     local Stats = Player:WaitForChild("leaderstats")
  87.     local Coins = Stats:WaitForChild("PizzaCoins")
  88.     if Coins.Value >= Cost and not Cool then
  89.         Cool = true
  90.         Coins.Value = Coins.Value - Cost
  91.         UnboxPet(Player)
  92.         wait(1)
  93.         Cool = false
  94.     end
  95. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top