HowToRoblox

BreakingHandler

Mar 6th, 2021
937
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local glass = script.Parent
  2.  
  3. local isBroken = false
  4.  
  5.  
  6. glass.Touched:Connect(function(hit)
  7.    
  8.  
  9.     if game.Players:GetPlayerFromCharacter(hit.Parent) and not isBroken then
  10.        
  11.         isBroken = true
  12.        
  13.        
  14.         local minX, maxX = glass.Position.X - glass.Size.X/2, glass.Position.X + glass.Size.X/2
  15.         local minY, maxY = glass.Position.Y - glass.Size.Y/2, glass.Position.Y + glass.Size.Y/2
  16.  
  17.         local pointOfBreak = Vector3.new(math.random(minX, maxX), math.random(minY, maxY), glass.Position.Z)
  18.        
  19.         local bottomLeft = Vector3.new(glass.Position.X - glass.Size.X/2, glass.Position.Y - glass.Size.Y/2, glass.Position.Z)
  20.         local topLeft = Vector3.new(glass.Position.X - glass.Size.X/2, glass.Position.Y + glass.Size.Y/2, glass.Position.Z)
  21.         local bottomRight = Vector3.new(glass.Position.X + glass.Size.X/2, glass.Position.Y - glass.Size.Y/2, glass.Position.Z)
  22.         local topRight = Vector3.new(glass.Position.X + glass.Size.X/2, glass.Position.Y + glass.Size.Y/2, glass.Position.Z)
  23.        
  24.        
  25.         local part1 = Instance.new("Part")
  26.         part1.Size = Vector3.new(pointOfBreak.X - bottomLeft.X, pointOfBreak.Y - bottomLeft.Y, glass.Size.Z)
  27.         part1.Position = Vector3.new(bottomLeft.X + part1.Size.X/2, bottomLeft.Y + part1.Size.Y/2, glass.Position.Z)
  28.        
  29.         local part2 = Instance.new("Part")
  30.         part2.Size = Vector3.new(pointOfBreak.X - topLeft.X, topLeft.Y - pointOfBreak.Y, glass.Size.Z)
  31.         part2.Position = Vector3.new(topLeft.X + part2.Size.X/2, topLeft.Y - part2.Size.Y/2, glass.Position.Z)
  32.        
  33.         local part3 = Instance.new("Part")
  34.         part3.Size = Vector3.new(bottomRight.X - pointOfBreak.X, pointOfBreak.Y - bottomRight.Y, glass.Size.Z)
  35.         part3.Position = Vector3.new(bottomRight.X - part3.Size.X/2, bottomRight.Y + part3.Size.Y/2, glass.Position.Z)
  36.        
  37.         local part4 = Instance.new("Part")
  38.         part4.Size = Vector3.new(topRight.X - pointOfBreak.X, topRight.Y - pointOfBreak.Y, glass.Size.Z)
  39.         part4.Position = Vector3.new(topRight.X - part4.Size.X/2, topRight.Y - part4.Size.Y/2, glass.Position.Z)
  40.        
  41.        
  42.         local wedges = {}
  43.        
  44.        
  45.         local wedge1 = Instance.new("WedgePart")
  46.         wedge1.Orientation = Vector3.new(0, -90, 180)
  47.         wedge1.Size = Vector3.new(part1.Size.Z, part1.Size.Y, part1.Size.X)
  48.         wedge1.Position = part1.Position
  49.         table.insert(wedges, wedge1)
  50.        
  51.         local wedge2 = Instance.new("WedgePart")
  52.         wedge2.Orientation = Vector3.new(0, 90, 0)
  53.         wedge2.Size = Vector3.new(part1.Size.Z, part1.Size.Y, part1.Size.X)
  54.         wedge2.Position = part1.Position
  55.         table.insert(wedges, wedge2)
  56.        
  57.        
  58.         local wedge3 = Instance.new("WedgePart")
  59.         wedge3.Orientation = Vector3.new(0, -90, 0)
  60.         wedge3.Size = Vector3.new(part2.Size.Z, part2.Size.Y, part2.Size.X)
  61.         wedge3.Position = part2.Position
  62.         table.insert(wedges, wedge3)
  63.  
  64.         local wedge4 = Instance.new("WedgePart")
  65.         wedge4.Orientation = Vector3.new(0, 90, 180)
  66.         wedge4.Size = Vector3.new(part2.Size.Z, part2.Size.Y, part2.Size.X)
  67.         wedge4.Position = part2.Position
  68.         table.insert(wedges, wedge4)
  69.        
  70.        
  71.         local wedge5 = Instance.new("WedgePart")
  72.         wedge5.Orientation = Vector3.new(0, -90, 0)
  73.         wedge5.Size = Vector3.new(part3.Size.Z, part3.Size.Y, part3.Size.X)
  74.         wedge5.Position = part3.Position
  75.         table.insert(wedges, wedge5)
  76.  
  77.         local wedge6 = Instance.new("WedgePart")
  78.         wedge6.Orientation = Vector3.new(0, 90, 180)
  79.         wedge6.Size = Vector3.new(part3.Size.Z, part3.Size.Y, part3.Size.X)
  80.         wedge6.Position = part3.Position
  81.         table.insert(wedges, wedge6)
  82.  
  83.  
  84.         local wedge7 = Instance.new("WedgePart")
  85.         wedge7.Orientation = Vector3.new(0, -90, 180)
  86.         wedge7.Size = Vector3.new(part4.Size.Z, part4.Size.Y, part4.Size.X)
  87.         wedge7.Position = part4.Position
  88.         table.insert(wedges, wedge7)
  89.  
  90.         local wedge8 = Instance.new("WedgePart")
  91.         wedge8.Orientation = Vector3.new(0, 90, 0)
  92.         wedge8.Size = Vector3.new(part4.Size.Z, part4.Size.Y, part4.Size.X)
  93.         wedge8.Position = part4.Position
  94.         table.insert(wedges, wedge8)
  95.        
  96.        
  97.         for i, wedge in pairs(wedges) do
  98.            
  99.             wedge.Material = Enum.Material.Glass
  100.             wedge.Transparency = 0.6
  101.             wedge.Color = Color3.fromRGB(159, 243, 233)
  102.            
  103.             wedge.Parent = workspace
  104.         end
  105.        
  106.        
  107.         glass.Transparency = 1
  108.         glass.CanCollide = false
  109.     end
  110. end)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×