Advertisement
DrawingJhon

PetBlock Button

Oct 16th, 2022 (edited)
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.85 KB | None | 0 0
  1. local Chat = game:GetService("Chat")
  2.  
  3. local function CreateButtonModel()
  4.     --Converted with ttyyuu12345's model to script plugin v4
  5.     Model0 = Instance.new("Model")
  6.     Part1 = Instance.new("Part")
  7.     Part2 = Instance.new("Part")
  8.     Script3 = Instance.new("Script")
  9.     ClickDetector4 = Instance.new("ClickDetector")
  10.     Part5 = Instance.new("Part")
  11.     Model0.Parent = mas
  12.     Model0.PrimaryPart = Part5
  13.     Part1.Parent = Model0
  14.     Part1.CFrame = CFrame.new(-4.5, 11.624999, 20.9999981, 1, 0, 0, 0, 0.866025388, -0.5, 0, 0.5, 0.866025388)
  15.     Part1.Orientation = Vector3.new(30, 0, 0)
  16.     Part1.Position = Vector3.new(-4.5, 11.624999046325684, 20.999998092651367)
  17.     Part1.Rotation = Vector3.new(30, 0, 0)
  18.     Part1.Color = Color3.new(0.0352941, 0.537255, 0.811765)
  19.     Part1.Size = Vector3.new(1.5, 0.75, 1.5)
  20.     Part1.Anchored = true
  21.     Part1.BottomSurface = Enum.SurfaceType.Smooth
  22.     Part1.BrickColor = BrickColor.new("Electric blue")
  23.     Part1.TopSurface = Enum.SurfaceType.Smooth
  24.     Part1.brickColor = BrickColor.new("Electric blue")
  25.     Part2.Name = "ButtonPart"
  26.     Part2.Parent = Model0
  27.     Part2.CFrame = CFrame.new(-4.5, 12.058012, 21.2499981, 1, 0, 0, 0, 0.866025388, -0.5, 0, 0.5, 0.866025388)
  28.     Part2.Orientation = Vector3.new(30, 0, 0)
  29.     Part2.Position = Vector3.new(-4.5, 12.058012008666992, 21.249998092651367)
  30.     Part2.Rotation = Vector3.new(30, 0, 0)
  31.     Part2.Color = Color3.new(0.0509804, 0.411765, 0.67451)
  32.     Part2.Size = Vector3.new(1, 0.25, 1)
  33.     Part2.Anchored = true
  34.     Part2.BottomSurface = Enum.SurfaceType.Smooth
  35.     Part2.BrickColor = BrickColor.new("Bright blue")
  36.     Part2.TopSurface = Enum.SurfaceType.Smooth
  37.     Part2.brickColor = BrickColor.new("Bright blue")
  38.     Script3.Name = "OnClicked"
  39.     Script3.Parent = Part2
  40.     ClickDetector4.Parent = Part2
  41.     Part5.Name = "SPart"
  42.     Part5.Parent = Model0
  43.     Part5.CFrame = CFrame.new(-4.5, 9.75, 21, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  44.     Part5.Position = Vector3.new(-4.5, 9.75, 21)
  45.     Part5.Color = Color3.new(0.0352941, 0.537255, 0.811765)
  46.     Part5.Size = Vector3.new(1, 3.5, 1)
  47.     Part5.Anchored = true
  48.     Part5.BottomSurface = Enum.SurfaceType.Smooth
  49.     Part5.BrickColor = BrickColor.new("Electric blue")
  50.     Part5.TopSurface = Enum.SurfaceType.Smooth
  51.     Part5.brickColor = BrickColor.new("Electric blue")
  52.     return Model0
  53. end
  54.  
  55. local function CreatePet()
  56.     --Converted with ttyyuu12345's model to script plugin v4
  57.     Model0 = Instance.new("Model")
  58.     Part1 = Instance.new("Part")
  59.     BodyPosition2 = Instance.new("BodyPosition")
  60.     BodyGyro3 = Instance.new("BodyGyro")
  61.     Humanoid4 = Instance.new("Humanoid")
  62.     Model0.Name = "Pet"
  63.     Model0.Parent = mas
  64.     Part1.Name = "Head"
  65.     Part1.Parent = Model0
  66.     Part1.CFrame = CFrame.new(-11.75, 9, 36.75, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  67.     Part1.Position = Vector3.new(-11.75, 9, 36.75)
  68.     Part1.Size = Vector3.new(1.5, 1.5, 1.5)
  69.     Part1.Anchored = true
  70.     Part1.BottomSurface = Enum.SurfaceType.Smooth
  71.     Part1.CanCollide = false
  72.     Part1.Material = Enum.Material.ForceField
  73.     Part1.TopSurface = Enum.SurfaceType.Smooth
  74.     BodyPosition2.Parent = Part1
  75.     BodyPosition2.Position = Vector3.new(0, 0, 0)
  76.     BodyPosition2.MaxForce = Vector3.one * math.huge
  77.     BodyPosition2.maxForce = Vector3.one * math.huge
  78.     BodyPosition2.position = Vector3.new(0, 0, 0)
  79.     BodyGyro3.Parent = Part1
  80.     BodyGyro3.MaxTorque = Vector3.one * math.huge
  81.     BodyGyro3.maxTorque = Vector3.one * math.huge
  82.     Humanoid4.Parent = Model0
  83.     return Model0
  84. end
  85.  
  86. local ButtonModel = CreateButtonModel()
  87. local ButtonPart = ButtonModel.ButtonPart
  88. local ClickDetector = ButtonPart.ClickDetector
  89. local SPart = ButtonModel.SPart
  90. local Pet = CreatePet()
  91.  
  92. local RunService = game:GetService("RunService")
  93.  
  94. ButtonModel.Parent = script
  95. ButtonModel:PivotTo(CFrame.new(11, 1.75, -17.5))
  96.  
  97. local function Repeat(num, min, max)
  98.     return num % (max - min) + min
  99. end
  100.  
  101. local SavedPets = {}
  102.  
  103. local PetMessages = {"I'm hungry!", "sup", "grrrr", "hellooo", "<name> you suck",
  104.     "<name> and I will conquer de world", "it's good to be alive", "stop touching me, pervert"}
  105.  
  106. local function SpawnPet(player, spawnPos)
  107.     local character = player.Character
  108.  
  109.     if SavedPets[character] then
  110.         return
  111.     end
  112.     print(player.Name.." has just got a pet!")
  113.  
  114.     local rootPart = character.HumanoidRootPart
  115.     local pet = Pet:Clone()
  116.     local petHuman = pet.Humanoid
  117.     local part = pet.Head
  118.     local bodyPos = part.BodyPosition
  119.     local bodyGyro = part.BodyGyro
  120.  
  121.     part.Position = spawnPos
  122.  
  123.     local dead = false
  124.  
  125.     petHuman:GetPropertyChangedSignal("Health"):Connect(function()
  126.         if petHuman.Health <= 0.01 and not dead then
  127.             dead = true
  128.             print(player.Name.."'s pet died :(")
  129.             part.CanCollide = true
  130.             bodyPos:Destroy()
  131.             bodyGyro:Destroy()
  132.             SavedPets[character] = nil
  133.             pet.Parent = workspace
  134.             part.Color = Color3.new(1, 0, 0)
  135.  
  136.             game:GetService("Debris"):AddItem(pet, 10)
  137.         end
  138.     end)
  139.  
  140.     bodyPos.Position = spawnPos
  141.     part.Anchored = false
  142.     pet.Name = player.Name.."'s pet"
  143.     petHuman.DisplayName = " "
  144.     SavedPets[character] = petHuman
  145.     pet.Parent = script
  146.  
  147.     if player.UserId == 652513366 or player == owner then
  148.         task.spawn(function()
  149.             while part:IsDescendantOf(workspace) and not dead do
  150.                 part.Color = Color3.fromHSV(Repeat(tick(), 0, 1), 1, 1)
  151.                 RunService.Heartbeat:Wait()
  152.             end
  153.         end)
  154.     end
  155.  
  156.     local offsetAngle = CFrame.new()
  157.  
  158.     coroutine.wrap(function()
  159.         while rootPart:IsDescendantOf(workspace) and not dead do
  160.             local cf = rootPart.CFrame * CFrame.new(2, 2, 3)
  161.             bodyPos.Position = cf.Position
  162.             bodyGyro.CFrame = cf * offsetAngle
  163.             RunService.Heartbeat:Wait()
  164.         end
  165.  
  166.         pet:Destroy()
  167.         SavedPets[character] = nil
  168.     end)()
  169.  
  170.     coroutine.wrap(function()
  171.         local petName = player.Name.."'s pet"
  172.  
  173.         for i = 1, #petName do
  174.             petHuman.DisplayName = petName:sub(1, i)
  175.             task.wait(0.05)
  176.         end
  177.     end)()
  178.  
  179.     local clicked = false
  180.     local cd = Instance.new("ClickDetector", part)
  181.    
  182.     local lastMessageTick = 0
  183.     local messageInterval = 3
  184.    
  185.     cd.MouseClick:Connect(function(plr)
  186.         if plr ~= player or clicked then
  187.             return
  188.         end
  189.         clicked = true
  190.        
  191.         task.delay(0.5, function()
  192.             if tick() - lastMessageTick >= messageInterval then
  193.                 lastMessageTick = tick()
  194.                 local message = PetMessages[math.random(#PetMessages)]:gsub("<name>", player.Name)
  195.                 Chat:Chat(part, message, Enum.ChatColor.White)
  196.             end
  197.         end)
  198.        
  199.         local startTick = tick()
  200.  
  201.         repeat
  202.             offsetAngle = CFrame.Angles(0, 0, math.rad(math.sin(tick() * 40) * 60))
  203.             RunService.Heartbeat:Wait()
  204.         until tick() - startTick >= 0.6
  205.  
  206.         offsetAngle = CFrame.new()
  207.  
  208.         task.wait(0.5)
  209.  
  210.         clicked = false
  211.     end)
  212. end
  213.  
  214. local function OnClicked(player)
  215.     ButtonPart.CFrame = ButtonPart.CFrame * CFrame.new(0, -ButtonPart.Size.Y + 0.1, 0)
  216.     SpawnPet(player, SPart.Position + Vector3.new(0, 5, 0))
  217.     task.wait(1.5)
  218.     ButtonPart.CFrame = ButtonPart.CFrame * CFrame.new(0, ButtonPart.Size.Y - 0.1, 0)
  219. end
  220.  
  221. local debounce = false
  222. ClickDetector.MouseClick:Connect(function(player)
  223.     if not debounce then
  224.         debounce = true
  225.         OnClicked(player)
  226.         debounce = false
  227.     end
  228. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement