KrYn0MoRe

terrain destruction

Apr 25th, 2021 (edited)
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.44 KB | None | 0 0
  1. local degrees = {
  2.     CFrame.Angles(math.rad(45),math.rad(0),math.rad(0)),
  3.     CFrame.Angles(math.rad(45),math.rad(45),math.rad(0)),
  4.     CFrame.Angles(math.rad(0),math.rad(0),math.rad(45)),
  5.     CFrame.Angles(math.rad(45),math.rad(0),math.rad(45)),
  6.     CFrame.Angles(math.rad(45),math.rad(45),math.rad(0)),
  7.     CFrame.Angles(math.rad(0),math.rad(45),math.rad(45)),
  8.     CFrame.Angles(math.rad(45),math.rad(45),math.rad(45)),
  9. }
  10.  
  11. local blacklisted = {
  12.     'Base',
  13.     'Baseplate',
  14. }
  15.  
  16. function make_crater(size,cf,mode)
  17.     local subtract = {}
  18.  
  19.     if mode == 1 then
  20.         for i = 1,#degrees do
  21.             local p = Instance.new("Part")
  22.             p.Size = Vector3.new(size,size,size)
  23.             p.Shape = Enum.PartType.Block
  24.             p.Anchored = true
  25.             p.CanCollide = false
  26.             p.Transparency = 0.5
  27.  
  28.             local angle = degrees[i]
  29.             angle = math.random()
  30.             p.CFrame = cf*angle
  31.             p.Parent = game.Lighting
  32.  
  33.             table.insert(subtract,1,p)
  34.         end
  35.     elseif mode == 2 then
  36.         for i = 1,1 do
  37.             local p = Instance.new("Part")
  38.             p.Size = Vector3.new(size,size,size)
  39.             p.Shape = Enum.PartType.Ball
  40.             p.Anchored = true
  41.             p.CanCollide = false
  42.             p.Transparency = 0.5
  43.  
  44.             p.CFrame = cf
  45.             p.Parent = game.Lighting
  46.  
  47.             table.insert(subtract,1,p)
  48.         end
  49.     elseif mode == 3 then
  50.         for i = 1,10 do
  51.             local p = Instance.new("Part")
  52.             p.Size = Vector3.new(size,size,size)
  53.             p.Shape = Enum.PartType.Block
  54.             p.Anchored = true
  55.             p.CanCollide = false
  56.             p.Transparency = 0.5
  57.  
  58.             local angle = CFrame.Angles(math.rad(math.random()*180),math.rad(math.random()*180),math.rad(math.random()*180))
  59.             p.CFrame = cf*angle
  60.             p.Parent = game.Lighting
  61.  
  62.             table.insert(subtract,1,p)
  63.         end
  64.     end
  65.  
  66.     assert(#subtract > 0,'No parts to union.')
  67.     local region = Region3.new(cf.p-Vector3.new(size,size,size)/2,cf.p+Vector3.new(size,size,size)/2)
  68.     local parts = workspace:FindPartsInRegion3WithIgnoreList(region,subtract,1/0)
  69.     for _,v in ipairs(parts) do
  70.         if v and v:IsA("BasePart") and not v.Parent:IsA("Accessory") and not v.Parent:FindFirstChildOfClass("Humanoid") and not table.find(blacklisted,v.Name) then
  71.             coroutine.wrap(function()
  72.                 local par = v.Parent
  73.                 v.Parent = game:GetService("Lighting")
  74.                 local union
  75.                 local success = pcall(function()
  76.                     union = v:SubtractAsync(subtract,Enum.CollisionFidelity.PreciseConvexDecomposition,Enum.RenderFidelity.Precise)
  77.                 end)
  78.                 if not union or not success then
  79.                     v:Destroy()
  80.                     return
  81.                 end
  82.                 union.Name = v.Name
  83.                 union.Anchored = v.Anchored
  84.                 union.CanCollide = v.CanCollide
  85.                 for _,vv in pairs(v:GetChildren()) do
  86.                     vv.Parent = union
  87.                 end
  88.                 v:Destroy()
  89.                 union.Parent = par
  90.             end)()
  91.         end
  92.     end
  93.     for i,v in ipairs(subtract) do v:Destroy() end
  94. end
  95.  
  96. local plr = owner
  97. local pgui = plr:FindFirstChildOfClass("PlayerGui")
  98. local remote = Instance.new("RemoteEvent")
  99. remote.Parent = pgui
  100.  
  101. remote.OnServerEvent:Connect(function(lplr,cf,radius)
  102.     if lplr == plr then else return end
  103.     make_crater(radius,cf,3)
  104. end)
  105.  
  106. warn([[
  107. == Made by KrYn0MoRe ==
  108. == KEYS ==
  109. e = radius 5
  110. r = radius 10
  111. t = radius 15
  112. y = radius 20
  113. ]])
  114.  
  115. NLS([[
  116. local remote = script.Parent
  117. local plr = game:GetService("Players").LocalPlayer
  118. local mouse = plr:GetMouse()
  119. mouse.KeyDown:Connect(function(key)
  120.     if key == 'e' then
  121.         remote:FireServer(mouse.Hit,5)
  122.     elseif key == 'r' then
  123.         remote:FireServer(mouse.Hit,10)
  124.     elseif key == 't' then
  125.         remote:FireServer(mouse.Hit,15)
  126.     elseif key == 'y' then
  127.         remote:FireServer(mouse.Hit,20)
  128.     end
  129. end)
  130. ]],remote)
Add Comment
Please, Sign In to add comment