Advertisement
TheDev321

Untitled

Jun 21st, 2021
1,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. local Module = {}
  2.  
  3. local Rep = game:GetService('ReplicatedStorage')
  4.     local Node = Rep.Node
  5.  
  6. function IsThisRoom(wall, fhit)
  7.     local itIs = false
  8.     local tries = 0
  9.  
  10.     if not itIs then
  11.         tries = tries + 1
  12.         local tp = wall:GetTouchingParts()
  13.         if #tp < 1 then
  14.             return false
  15.         else
  16.             for _, hit in pairs(tp) do
  17.                 if hit.Name == "1" or hit.Name == '2' then
  18.                     if hit ~= fhit then
  19.                         if not itIs then
  20.                             if hit.Parent == fhit.Parent then
  21.                                 itIs = true
  22.                                 ThisIsRoom(wall.Parent)
  23.                             else
  24.                                 rec(hit, wall)
  25.                             end
  26.                         end
  27.                     end
  28.                 end
  29.             end
  30.         end
  31.     else
  32.         return
  33.     end
  34.  
  35.     return itIs
  36. end
  37.  
  38. function ThisIsRoom(room)
  39.     local color = BrickColor.Green()
  40.     for _, wall in pairs(room:GetChildren()) do
  41.         wall.BrickColor = color
  42.     end
  43. end
  44.  
  45. local WALLS = {}
  46.  
  47. function Module:MakeRoom()
  48.     local walls = workspace.Assets.Walls
  49.  
  50.     walls.ChildAdded:Connect(function(Child)
  51.         local Model = workspace:FindFirstChild('Wall')
  52.         if Model == nil then
  53.             Model = Instance.new("Model", workspace)
  54.             Model.Name = "Wall"
  55.         end
  56.        
  57.         wait(0.05)
  58.         Child.Parent = Model
  59.         table.insert(WALLS, Child)         
  60.     end)
  61.  
  62.     for v, wall in pairs(WALLS) do
  63.         for k, wall2 in pairs(WALLS) do
  64.             for a, i in pairs(wall2.Hitbox:GetChildren()) do
  65.                 for b, n in pairs(wall.Hitbox:GetChildren()) do
  66.                     rec(i, n)
  67.                 end
  68.             end
  69.             --rec(wall2.Hitbox, wall.Hitbox)
  70.         end
  71.     end
  72. end
  73.  
  74. function rec(wall, preferedwall)
  75.     if preferedwall == nil then
  76.         local localParent = wall.Parent
  77.         --Touch
  78.         local t = wall.Touched:Connect(function() end)
  79.         local tp = wall:GetTouchingParts()
  80.         t:Disconnect()
  81.         if #tp < 1 then return end
  82.        
  83.         for _, hit in ipairs(tp) do
  84.             if hit.Name == "1" or hit.Name == '2' then
  85.                 local otherParent = hit.Parent
  86.                 if otherParent ~= localParent then
  87.                     wall.Parent = otherParent
  88.                     local room = IsThisRoom(wall, hit)
  89.                     if room then
  90.                         ThisIsRoom(otherParent)
  91.                         wall.Parent.Name = "ROOM"
  92.                     end
  93.                 else
  94.  
  95.                 end
  96.             end
  97.         end
  98.     else
  99.         wall.Parent = preferedwall.Parent
  100.         local room = IsThisRoom(wall, preferedwall)
  101.         if room then
  102.             ThisIsRoom(preferedwall.Parent)
  103.             wall.Parent.Name = "ROOM"
  104.         end
  105.     end
  106. end
  107.  
  108. workspace.Assets.Walls.ChildAdded:Connect(function(Child)
  109.     local Model = workspace.Assets.Walls
  110.    
  111.     wait(0.05)
  112.     Child.Parent = Model
  113.     table.insert(WALLS, Child)
  114.  
  115.     for v, wall in pairs(WALLS) do
  116.         if wall:FindFirstChild('Hitbox') then
  117.             for b, n in pairs(wall.Hitbox:GetChildren()) do
  118.                 rec(n)
  119.             end
  120.         end
  121.     end
  122. end)
  123.  
  124. return Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement