_James

Node Connector

Jun 14th, 2016
1,423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.60 KB | None | 0 0
  1. local Nodes = workspace:WaitForChild("Nodes")
  2. local Table = Nodes:GetChildren()
  3.  
  4. function Connect()
  5.     for _,A in ipairs(Table)do
  6.         -- Don't overfill the nodes with neighbors.
  7.         if #A:GetChildren() <= 0 then
  8.             for _,B in ipairs(Table)do
  9.                 if B ~= A then
  10.                     -- Make sure the path can be completed.
  11.                     local P = workspace:FindPartOnRay(Ray.new(A.Position, B.Position - A.Position))
  12.                    
  13.                     if P == B then
  14.                         local Neighbor = Instance.new("ObjectValue")
  15.                         Neighbor.Value = B
  16.                         Neighbor.Name = "Neighbor"
  17.                         Neighbor.Parent = A
  18.                     end
  19.                 end
  20.             end
  21.         end
  22.     end
  23. end
  24.  
  25. Connect()
Advertisement
Add Comment
Please, Sign In to add comment