Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  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 RangePart = UnCommon.RangePartUnCommon
  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.  
  85. RangePart.Touched:Connect(function(hit)
  86. local H = hit.Parent:FindFirstChild("Humanoid")
  87.     if H then
  88. local player = game.Players.LocalPlayer
  89. local Mouse = player:GetMouse()
  90. Mouse.KeyDown:Connect(function(key)
  91. if key == "e" then
  92.  local Stats = Player:WaitForChild("leaderstats")
  93.     local Coins = Stats:WaitForChild("PizzaCoins")
  94.     if Coins.Value >= Cost then
  95.         Coins.Value = Coins.Value - Cost
  96.         UnboxPet(Player)
  97.     end
  98. end
  99. end)
  100. end
  101. end)
  102.     end
  103. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement