Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local character = game.Workspace:WaitForChild(player.Name)
- local mouse = player:GetMouse()
- local tool = script.Parent
- local canClick = false
- local run = game:GetService("RunService")
- local rep = game:GetService("ReplicatedStorage")
- local seg = rep.Segment
- local cam = game.Workspace.CurrentCamera
- function createPipe()
- if canClick == true and disp then
- pcall(function()
- local numbers = {}
- for i,v in pairs(targparent:GetChildren()) do
- table.insert(numbers, #numbers+1, tonumber(string.sub(v.Name, 8)))
- end
- table.sort(numbers)
- newSegment = seg:Clone()
- newSegment.Parent = targparent
- newSegment.CFrame = disp.CFrame
- newSegment.Name = "Segment"..numbers[#numbers]+1
- end)
- end
- end
- function addPipe()
- local target = mouse.Target
- if target then
- if string.sub(target.Name, 1, 7) == "Segment" then
- targparent = target.Parent
- local mousesurface = string.sub(tostring(mouse.TargetSurface), 15)
- local surfaces = {"Top", "Bottom", "Back", "Front", "Right", "Left"}
- 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)}
- for i=1, #surfaces do
- if mousesurface == surfaces[i] then
- surface = cf[i]
- end
- end
- if not disp then
- if tonumber(string.sub(target.Name, 8)) == #target.Parent:GetChildren()-1 then
- disp = seg:Clone()
- disp.Name = "Display"
- disp.Parent = cam
- disp.Transparency = 0.5
- disp.CanCollide = false
- disp.CFrame = target.CFrame * CFrame.new(surface)
- end
- else
- if mousesurface ~= lastsurface then
- disp:destroy()
- disp = nil
- end
- end
- local lastsurface = mousesurface
- end
- if disp then
- canClick = true
- if string.sub(target.Name, 1, 7) ~= "Segment" and string.sub(target.Name, 1, 7) ~= "Display" then
- disp:Destroy()
- disp = nil
- end
- else
- canClick = false
- end
- else
- if disp then
- disp:Destroy()
- disp = nil
- end
- end
- end
- function removePipe()
- local target = mouse.Target
- if target then
- if string.sub(target.Name, 1, 7) == "Segment" and target.Name ~= "Segment1" then
- for i,v in pairs(target.Parent:GetChildren()) do
- if v:IsA("UnionOperation") then
- if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(target.Name, 8)) then
- v:Destroy()
- end
- end
- end
- target:Destroy()
- end
- end
- end
- function deletePipe()
- local target = mouse.Target
- if target then
- if string.sub(target.Name, 1, 7) == "Segment" and target.Name ~= "Segment1" then
- if lasttarget ~= target and lasttarget then
- pcall(function()
- for i,v in pairs(lasttarget.Parent:GetChildren()) do
- if v:IsA("UnionOperation") then
- if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(lasttarget.Name, 8)) then
- v.Transparency = 0
- end
- end
- end
- end)
- lasttarget.Transparency = 0
- else
- for i,v in pairs(target.Parent:GetChildren()) do
- if v:IsA("UnionOperation") then
- if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(target.Name, 8)) then
- v.Transparency = 0.5
- end
- end
- end
- target.Transparency = 0.5
- end
- lasttarget = target
- else
- if lasttarget then
- pcall(function()
- for i,v in pairs(lasttarget.Parent:GetChildren()) do
- if v:IsA("UnionOperation") then
- if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(lasttarget.Name, 8)) then
- v.Transparency = 0
- end
- end
- end
- end)
- lasttarget.Transparency = 0
- end
- end
- end
- end
- function ChangeSetting(key)
- if key == "q" or key == "e" then
- if disp then
- disp:Destroy()
- disp = nil
- end
- if lasttarget and lasttarget.Parent then
- for i,v in pairs(lasttarget.Parent:GetChildren()) do
- if v:IsA("UnionOperation") then
- if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(lasttarget.Name, 8)) then
- v.Transparency = 0
- end
- end
- end
- lasttarget.Transparency = 0
- end
- if con1 then con1:disconnect() con1 = nil end
- if con2 then con2:disconnect() con2 = nil end
- if key ~= currentkey then
- if key == "q" then
- con1 = run.Stepped:connect(addPipe)
- con2 = mouse.Button1Down:connect(createPipe)
- elseif key == "e" then
- con1 = run.Stepped:connect(deletePipe)
- con2 = mouse.Button1Down:connect(removePipe)
- end
- currentkey = key
- else
- currentkey = nil
- end
- end
- end
- character.Humanoid.Died:connect(function()
- if con1 then con1:disconnect() end
- if con2 then con2:disconnect() end
- if dead then dead:disconnect() end
- if cam:FindFirstChild("Display") then
- cam.Display:Destroy()
- end
- if lasttarget then
- for i,v in pairs(lasttarget.Parent:GetChildren()) do
- if v:IsA("UnionOperation") then
- if tonumber(string.sub(v.Name, 8)) > tonumber(string.sub(lasttarget.Name, 8)) then
- v.Transparency = 0
- end
- end
- end
- lasttarget.Transparency = 0
- end
- end)
- dead = mouse.KeyDown:connect(ChangeSetting)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement