Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local character = game.Workspace:WaitForChild(player.Name)
  3. local mouse = player:GetMouse()
  4. local tool = script.Parent
  5. local canClick = false
  6. local run = game:GetService("RunService")
  7. local rep = game:GetService("ReplicatedStorage")
  8. local seg = rep.Segment
  9. local cam = game.Workspace.CurrentCamera
  10.  
  11. function createPipe()
  12. if canClick == true and disp then
  13. pcall(function()
  14. local numbers = {}
  15. for i,v in pairs(targparent:GetChildren()) do
  16. table.insert(numbers, #numbers+1, tonumber(string.sub(v.Name, 8)))
  17. end
  18. table.sort(numbers)
  19. newSegment = seg:Clone()
  20. newSegment.Parent = targparent
  21. newSegment.CFrame = disp.CFrame
  22. newSegment.Name = "Segment"..numbers[#numbers]+1
  23. end)
  24. end
  25. end
  26.  
  27. function addPipe()
  28. local target = mouse.Target
  29. if target then
  30. if string.sub(target.Name, 1, 7) == "Segment" then
  31. targparent = target.Parent
  32. local mousesurface = string.sub(tostring(mouse.TargetSurface), 15)
  33. local surfaces = {"Top", "Bottom", "Back", "Front", "Right", "Left"}
  34. local cf = {Vector3.new(0, target.Size.Y, 0), Vector3.new(0, -target.Size.Y, 0), Vector3.new(0, 0, target.Size.Z), Vector3.new(0, 0, -target.Size.Z), Vector3.new(target.Size.X, 0, 0), Vector3.new(-target.Size.X, 0, 0)}
  35. for i=1, #surfaces do
  36. if mousesurface == surfaces[i] then
  37. surface = cf[i]
  38. end
  39. end
  40. if not disp then
  41. if tonumber(string.sub(target.Name, 8)) == #target.Parent:GetChildren()-1 then
  42. disp = seg:Clone()
  43. disp.Name = "Display"
  44. disp.Parent = cam
  45. disp.Transparency = 0.5
  46. disp.CanCollide = false
  47. disp.CFrame = target.CFrame * CFrame.new(surface)
  48. end
  49. else
  50. if mousesurface ~= lastsurface then
  51. disp:destroy()
  52. disp = nil
  53. end
  54. end
  55. local lastsurface = mousesurface
  56. end
  57. if disp then
  58. canClick = true
  59. if string.sub(target.Name, 1, 7) ~= "Segment" and string.sub(target.Name, 1, 7) ~= "Display" then
  60. disp:Destroy()
  61. disp = nil
  62. end
  63. else
  64. canClick = false
  65. end
  66. else
  67. if disp then
  68. disp:Destroy()
  69. disp = nil
  70. end
  71. end
  72. end
  73.  
  74. function removePipe()
  75. local target = mouse.Target
  76. if target then
  77. if string.sub(target.Name, 1, 7) == "Segment" and target.Name ~= "Segment1" then
  78. for i,v in pairs(target.Parent:GetChildren()) do
  79. if v:IsA("UnionOperation") then
  80. if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(target.Name, 8)) then
  81. v:Destroy()
  82. end
  83. end
  84. end
  85. target:Destroy()
  86. end
  87. end
  88. end
  89.  
  90. function deletePipe()
  91. local target = mouse.Target
  92. if target then
  93. if string.sub(target.Name, 1, 7) == "Segment" and target.Name ~= "Segment1" then
  94. if lasttarget ~= target and lasttarget then
  95. pcall(function()
  96. for i,v in pairs(lasttarget.Parent:GetChildren()) do
  97. if v:IsA("UnionOperation") then
  98. if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(lasttarget.Name, 8)) then
  99. v.Transparency = 0
  100. end
  101. end
  102. end
  103. end)
  104. lasttarget.Transparency = 0
  105. else
  106. for i,v in pairs(target.Parent:GetChildren()) do
  107. if v:IsA("UnionOperation") then
  108. if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(target.Name, 8)) then
  109. v.Transparency = 0.5
  110. end
  111. end
  112. end
  113. target.Transparency = 0.5
  114. end
  115. lasttarget = target
  116. else
  117. if lasttarget then
  118. pcall(function()
  119. for i,v in pairs(lasttarget.Parent:GetChildren()) do
  120. if v:IsA("UnionOperation") then
  121. if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(lasttarget.Name, 8)) then
  122. v.Transparency = 0
  123. end
  124. end
  125. end
  126. end)
  127. lasttarget.Transparency = 0
  128. end
  129. end
  130. end
  131. end
  132.  
  133. function ChangeSetting(key)
  134. if key == "q" or key == "e" then
  135. if disp then
  136. disp:Destroy()
  137. disp = nil
  138. end
  139. if lasttarget and lasttarget.Parent then
  140. for i,v in pairs(lasttarget.Parent:GetChildren()) do
  141. if v:IsA("UnionOperation") then
  142. if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(lasttarget.Name, 8)) then
  143. v.Transparency = 0
  144. end
  145. end
  146. end
  147. lasttarget.Transparency = 0
  148. end
  149. if con1 then con1:disconnect() con1 = nil end
  150. if con2 then con2:disconnect() con2 = nil end
  151. if key ~= currentkey then
  152. if key == "q" then
  153. con1 = run.Stepped:connect(addPipe)
  154. con2 = mouse.Button1Down:connect(createPipe)
  155. elseif key == "e" then
  156. con1 = run.Stepped:connect(deletePipe)
  157. con2 = mouse.Button1Down:connect(removePipe)
  158. end
  159. currentkey = key
  160. else
  161. currentkey = nil
  162. end
  163. end
  164. end
  165.  
  166. character.Humanoid.Died:connect(function()
  167. if con1 then con1:disconnect() end
  168. if con2 then con2:disconnect() end
  169. if dead then dead:disconnect() end
  170. if cam:FindFirstChild("Display") then
  171. cam.Display:Destroy()
  172. end
  173. if lasttarget then
  174. for i,v in pairs(lasttarget.Parent:GetChildren()) do
  175. if v:IsA("UnionOperation") then
  176. if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(lasttarget.Name, 8)) then
  177. v.Transparency = 0
  178. end
  179. end
  180. end
  181. lasttarget.Transparency = 0
  182. end
  183. end)
  184.  
  185. dead = mouse.KeyDown:connect(ChangeSetting)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement