Advertisement
Vaeb

My Portals

Aug 22nd, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.45 KB | None | 0 0
  1. wait(1/30)
  2. --script.Parent = nil
  3.  
  4. local Plrs = game:GetService("Players")
  5. local RS = game:GetService("RunService")
  6. local LP = Plrs.LocalPlayer
  7. local Mouse = LP:GetMouse()
  8. local Char = LP.Character
  9. local isRemoving = {}
  10. local isMoving = {}
  11. local Debounces = {}
  12. local isTeleporting = false
  13. local LastPortalNum = 1
  14.  
  15. pcall(function() workspace["Portals"]:Destroy() end)
  16.  
  17. local Model = Instance.new("Model")
  18. Model.Name = "Portals"
  19. Model.Parent = workspace
  20.  
  21. ------------------------------------------------------------------------------------------------------------------------------------------------------
  22.  
  23. function removePortal(StringNum)
  24.     if not Model or not Model.Parent then
  25.         Model = Instance.new("Model")
  26.         Model.Name = "Portals"
  27.         Model.Parent = workspace
  28.     end
  29.     if Model:findFirstChild(StringNum) then
  30.         local PortalP = Model[StringNum]
  31.         local PortalPM = PortalP["PortalPM"]
  32.         isRemoving[PortalP] = true
  33.         PortalP.Name = "Removing"
  34.  
  35.         if PortalPM.Transparency < 1 then
  36.             for i = 0, 90, 3 do
  37.                 PortalPM.Transparency = math.max(math.sin(math.rad(i)), PortalPM.Transparency)
  38.                 RS.Heartbeat:wait()
  39.             end
  40.         end
  41.         PortalPM:Destroy()
  42.  
  43.         local PortalPSize = PortalP.Size
  44.         local PortalPCFrame = PortalP.CFrame
  45.         for i = 0, 1, 0.25 do
  46.             PortalP.Size = PortalPSize:lerp(Vector3.new(9, 0.3, 9), i)
  47.             PortalP.CFrame = PortalPCFrame
  48.             RS.Heartbeat:wait()
  49.         end
  50.  
  51.         PortalPSize = PortalP.Size
  52.         for i = 0, 1, 0.2 do
  53.             PortalP.Size = PortalPSize:lerp(Vector3.new(0, 0.3, 0), i)
  54.             PortalP.CFrame = PortalPCFrame
  55.             RS.Heartbeat:wait()
  56.         end
  57.  
  58.         PortalP:Destroy()
  59.  
  60.         isTeleporting = false
  61.  
  62.         isRemoving[PortalP] = nil
  63.         return true
  64.     end
  65.     return false
  66. end
  67.  
  68. function makePortal(Num, Hit, Target, Surface)
  69.     local StringNum = tostring(Num)
  70.     isMoving[Num] = nil
  71.     LastPortalNum = Num
  72.  
  73.     local Num2 = 1
  74.     if Num == 1 then
  75.         Num2 = 2
  76.     end
  77.     local StringNum2 = tostring(Num2)
  78.  
  79.     local TargetAng = Target.CFrame - Target.CFrame.p
  80.     local offsetCFrame = CFrame.new(Hit.p) * TargetAng
  81.  
  82.     if Surface ~= Enum.NormalId.Top then
  83.         print(Target.Name)
  84.     end
  85.  
  86.     if Surface == Enum.NormalId.Top then
  87.         offsetCFrame = offsetCFrame
  88.     elseif Surface == Enum.NormalId.Bottom then
  89.         offsetCFrame = offsetCFrame * CFrame.Angles(0, 0, math.rad(180))
  90.     elseif Surface == Enum.NormalId.Front then
  91.         offsetCFrame = offsetCFrame * CFrame.Angles(math.rad(-90), 0, 0)
  92.     elseif Surface == Enum.NormalId.Back then
  93.         offsetCFrame = offsetCFrame * CFrame.Angles(math.rad(90), 0, 0)
  94.     elseif Surface == Enum.NormalId.Left then
  95.         offsetCFrame = offsetCFrame * CFrame.Angles(0, 0, math.rad(90))
  96.     elseif Surface == Enum.NormalId.Right then
  97.         offsetCFrame = offsetCFrame * CFrame.Angles(0, 0, math.rad(-90))
  98.     end
  99.  
  100.     local PortalP = Instance.new("Part")
  101.     PortalP.Name = StringNum
  102.     PortalP.Material = "Plastic"
  103.     PortalP.FormFactor = "Custom"
  104.     PortalP.Color = Color3.new(0, 0, 0)
  105.     PortalP.Transparency = 0
  106.     PortalP.Anchored = true
  107.     PortalP.CanCollide = true
  108.     PortalP.Locked = true
  109.     PortalP.BottomSurface, PortalP.TopSurface = "Smooth", "Smooth"
  110.     PortalP.Size = Vector3.new(0, 0.3, 0)
  111.     PortalP.CFrame = offsetCFrame * CFrame.new(0, 0.15, 0)
  112.     PortalP.Parent = Model
  113.  
  114.     local CylMesh = Instance.new("CylinderMesh", PortalP)
  115.     CylMesh.Name = "CylMesh"
  116.  
  117.     local PortalPM = Instance.new("Part")
  118.     PortalPM.Name = "PortalPM"
  119.     PortalPM.Material = "Plastic"
  120.     PortalPM.FormFactor = "Custom"
  121.     PortalPM.Color = Color3.new(1, 1, 1)
  122.     PortalPM.Transparency = 1
  123.     PortalPM.Anchored = true
  124.     PortalPM.CanCollide = true
  125.     PortalPM.Locked = true
  126.     PortalPM.BottomSurface, PortalPM.TopSurface = "Smooth", "Smooth"
  127.     PortalPM.Size = Vector3.new(5, 0.2, 5)
  128.     PortalPM.CFrame = PortalP.CFrame * CFrame.new(0, 0.15, 0)
  129.     PortalPM.Parent = PortalP
  130.  
  131.     local CylMesh = Instance.new("CylinderMesh", PortalP)
  132.     CylMesh.Name = "CylMesh"
  133.  
  134.     local CylMeshM = Instance.new("CylinderMesh", PortalPM)
  135.     CylMeshM.Name = "CylMeshM"
  136.  
  137.     coroutine.wrap(function()
  138.         while Model.Parent and PortalP.Parent and PortalPM.Parent do
  139.             if isMoving[Num] == nil then
  140.                 PortalP.CFrame = offsetCFrame * CFrame.new(0, 0.15, 0)
  141.                 PortalPM.CFrame = offsetCFrame * CFrame.new(0, 0.3, 0)
  142.             end
  143.             RS.Heartbeat:wait()
  144.         end
  145.     end)()
  146.  
  147.     local PortalPSize = PortalP.Size
  148.     for i = 0, 1, 0.1 do
  149.         if isRemoving[PortalP] then
  150.             return
  151.         end
  152.         PortalP.Size = PortalPSize:lerp(Vector3.new(9, 0.3, 9), i)
  153.         PortalP.CFrame = offsetCFrame * CFrame.new(0, 0.15, 0)
  154.         RS.Heartbeat:wait()
  155.     end
  156.  
  157.     coroutine.wrap(function()
  158.         local PortalCF = PortalPM.CFrame
  159.         local PortalCF2 = PortalCF * CFrame.new(1.4, 0, 0)
  160.         local PortalCF3 = PortalCF * CFrame.new(-1.4, 0, 0)
  161.         local PortalCF4 = PortalCF * CFrame.new(0, 0, 1.4)
  162.         local PortalCF5 = PortalCF * CFrame.new(0, 0, -1.4)
  163.         local Dist1 = (PortalCF.p - (PortalCF * CFrame.new(0, -1, 0)).p).unit * 8
  164.         local Dist2 = (PortalCF2.p - (PortalCF2 * CFrame.new(0, -1, 0)).p).unit * 8
  165.         local Dist3 = (PortalCF3.p - (PortalCF3 * CFrame.new(0, -1, 0)).p).unit * 8
  166.         local Dist4 = (PortalCF4.p - (PortalCF4 * CFrame.new(0, -1, 0)).p).unit * 8
  167.         local Dist5 = (PortalCF5.p - (PortalCF5 * CFrame.new(0, -1, 0)).p).unit * 8
  168.         while Model.Parent and PortalP.Parent and PortalPM.Parent do
  169.             local TouchRay1 = Ray.new(PortalCF.p, Dist1)
  170.             local TouchRay2 = Ray.new(PortalCF2.p, Dist2)
  171.             local TouchRay3 = Ray.new(PortalCF3.p, Dist3)
  172.             local TouchRay4 = Ray.new(PortalCF4.p, Dist4)
  173.             local TouchRay5 = Ray.new(PortalCF5.p, Dist5)
  174.             local Obj1, ObjPos1 = workspace:FindPartOnRay(TouchRay1, Model, false, true)
  175.             local Obj2, ObjPos2 = workspace:FindPartOnRay(TouchRay2, Model, false, true)
  176.             local Obj3, ObjPos3 = workspace:FindPartOnRay(TouchRay3, Model, false, true)
  177.             local Obj4, ObjPos4 = workspace:FindPartOnRay(TouchRay4, Model, false, true)
  178.             local Obj5, ObjPos5 = workspace:FindPartOnRay(TouchRay5, Model, false, true)
  179.             local Obj = nil
  180.             if Obj1 then
  181.                 Obj = Obj1
  182.             elseif Obj2 then
  183.                 Obj = Obj2
  184.             elseif Obj3 then
  185.                 Obj = Obj3
  186.             elseif Obj4 then
  187.                 Obj = Obj4
  188.             elseif Obj5 then
  189.                 Obj = Obj5
  190.             end
  191.             if Obj and PortalP.Name ~= "Removing" and isRemoving[PortalP] == nil and Model:findFirstChild(StringNum2) and Obj.Parent.ClassName == "Model" and Obj.Parent:findFirstChild("Torso") and isTeleporting == false and Debounces[Obj.Parent] == nil then
  192.                 local PortalP2 = Model[StringNum2]
  193.                 local ObjChar = Obj.Parent
  194.                 isTeleporting = true
  195.                 Debounces[ObjChar] = tick()
  196.                 local Portal2CF = PortalP2.PortalPM.CFrame
  197.                 local hasTeleported = false
  198.                 local isDone = false
  199.                 local oldRotation = ObjChar.Torso.CFrame - ObjChar.Torso.CFrame.p
  200.                 --ObjChar.Torso.Anchored = true
  201.                 --ObjChar.Torso.CFrame = CFrame.new((PortalPM.CFrame * CFrame.new(0, 3, 0)).p) * oldRotation
  202.                 for iNum = 1, 2 do
  203.                     local nowPortal = PortalPM
  204.                     if iNum == 2 then
  205.                         nowPortal = PortalP2.PortalPM
  206.                     end
  207.                     coroutine.wrap(function()
  208.                         for spinNum = 1, 6 do
  209.                             coroutine.wrap(function()
  210.                                 local nowPortalCFrame = nowPortal.CFrame
  211.                                 local origAng = math.rad(360/6*spinNum)
  212.                                 local miniBall = nowPortal:Clone()
  213.                                 miniBall.Transparency = 1
  214.                                 miniBall.Parent = nowPortal
  215.                                 miniBall:ClearAllChildren()
  216.                                 miniBall.Shape = "Ball"
  217.                                 miniBall.Material = "Neon"
  218.                                 miniBall.CanCollide = false
  219.                                 miniBall.Color = Color3.new(1, 1, 1)
  220.                                 miniBall.Size = Vector3.new(1, 1, 1)
  221.                                 miniBall.CFrame = nowPortalCFrame * CFrame.Angles(0, origAng, 0) * CFrame.new(0, 1, -4)
  222.  
  223.                                 local SphereMesh = Instance.new("SpecialMesh", miniBall)
  224.                                 SphereMesh.Name = "SphereMesh"
  225.                                 SphereMesh.MeshType = "Sphere"
  226.                                 SphereMesh.Scale = Vector3.new(1, 1, 1)
  227.  
  228.                                 for i = 90, 0, -10 do
  229.                                     miniBall.Transparency = math.sin(math.rad(i))
  230.                                     RS.Heartbeat:wait()
  231.                                 end
  232.                                 miniBall.Transparency = 0
  233.  
  234.                                 wait(1/30)
  235.  
  236.                                 local oldCF = miniBall.CFrame
  237.                                 local newCF = oldCF * CFrame.new(0, 6, 0)
  238.                                 for i = 0, 90, 9 do
  239.                                     miniBall.CFrame = oldCF:lerp(newCF, math.sin(math.rad(i)))
  240.                                     RS.Heartbeat:wait()
  241.                                 end
  242.                                 miniBall.CFrame = newCF
  243.                                 isDone = true
  244.  
  245.                                 repeat wait(.1) until hasTeleported == true
  246.                                 wait(1/30)
  247.  
  248.                                 local oldSize = SphereMesh.Scale
  249.                                 local newSize = Vector3.new(0, 0, 0)
  250.                                 for i = 0, 720, 36 do
  251.                                     local downNum = (i/360)
  252.                                     SphereMesh.Scale = oldSize:lerp(newSize, i/720)
  253.                                     miniBall.CFrame = nowPortalCFrame * CFrame.Angles(0, origAng + math.rad(i), 0) * CFrame.new(0, (7 - downNum), -4)
  254.                                     RS.Heartbeat:wait()
  255.                                 end
  256.                                 miniBall:Destroy()
  257.                                 isTeleporting = false
  258.                             end)()
  259.                         end
  260.                     end)()
  261.                 end
  262.                 repeat wait(1/30) until isDone == true
  263.                 for i = 1, 10 do
  264.                     ObjChar.Torso.CFrame = CFrame.new((Portal2CF * CFrame.new(0, 3, 0)).p) * oldRotation
  265.                 end
  266.                 --ObjChar.Torso.Anchored = false
  267.                 hasTeleported = true
  268.                 wait(3)
  269.                 Debounces[ObjChar] = nil
  270.             end
  271.             RS.Heartbeat:wait()
  272.         end
  273.     end)()
  274.  
  275.     PortalPSize = PortalP.Size
  276.     for i = 0, 1, 0.25 do
  277.         if isRemoving[PortalP] then
  278.             return
  279.         end
  280.         PortalP.Size = PortalPSize:lerp(Vector3.new(6, 0.3, 6), i)
  281.         PortalP.CFrame = offsetCFrame * CFrame.new(0, 0.15, 0)
  282.         RS.Heartbeat:wait()
  283.     end
  284.  
  285.     for i = 90, 0, -3 do
  286.         if isRemoving[PortalP] then
  287.             return
  288.         end
  289.         PortalPM.Transparency = math.sin(math.rad(i))
  290.         RS.Heartbeat:wait()
  291.     end
  292.     PortalPM.Transparency = 0
  293.  
  294.     coroutine.wrap(function()
  295.         wait(1)
  296.         while PortalP.Parent and Model.Parent do
  297.             local oldCFs = {}
  298.             local trueCFs = {}
  299.             local newParts = {}
  300.             local isDone = false
  301.             for i = 0, 1 do
  302.                 coroutine.wrap(function()
  303.                     local newPart = PortalP:Clone()
  304.                     newPart.Parent = PortalP
  305.                     newPart:ClearAllChildren()
  306.                     newPart.Color = Color3.new(1, 1, 1)
  307.                     newPart.Material = "Neon"
  308.                     newPart.Size = Vector3.new(0, 0.2, 0)
  309.                     newPart.CFrame = PortalP.CFrame * CFrame.new(0, -0.05, 0) * CFrame.Angles(0, math.rad(90)*i, 0)
  310.                     table.insert(newParts, newPart)
  311.                     trueCFs[newPart] = PortalP.CFrame * CFrame.new(0, -0.05, 0) * CFrame.Angles(0, math.rad(90)*i, 0)
  312.  
  313.                     local newPartSize = newPart.Size
  314.                     for i = 0, 1, 0.1 do
  315.                         if isRemoving[PortalP] then
  316.                             newPart:Destroy()
  317.                             return
  318.                         end
  319.                         newPart.Size = newPartSize:lerp(Vector3.new(12, 0.2, 0.2), i)
  320.                         newPart.CFrame = trueCFs[newPart]
  321.                         RS.Heartbeat:wait()
  322.                     end
  323.  
  324.                     newPartSize = newPart.Size
  325.                     for i = 0, 1, 0.25 do
  326.                         if isRemoving[PortalP] then
  327.                             newPart:Destroy()
  328.                             return
  329.                         end
  330.                         newPart.Size = newPartSize:lerp(Vector3.new(10, 0.2, 0.2), i)
  331.                         newPart.CFrame = trueCFs[newPart]
  332.                         RS.Heartbeat:wait()
  333.                     end
  334.  
  335.                     isDone = true
  336.                 end)()
  337.             end
  338.             repeat wait(1/30) until isDone == true
  339.             if isRemoving[PortalP] then
  340.                 for _,v in pairs(newParts) do
  341.                     v:Destroy()
  342.                 end
  343.                 return
  344.             end
  345.  
  346.             oldCFs[PortalP] = PortalP.CFrame
  347.             for _,v in pairs(PortalP:GetChildren()) do
  348.                 if trueCFs[v] then
  349.                     oldCFs[v] = trueCFs[v]
  350.                 elseif v:IsA("BasePart") then
  351.                     oldCFs[v] = v.CFrame
  352.                 end
  353.             end
  354.  
  355.             isMoving[Num] = true
  356.             for i = 0, 1.0001, 0.05 do
  357.                 if isRemoving[PortalP] then
  358.                     for _,v in pairs(newParts) do
  359.                         v:Destroy()
  360.                     end
  361.                     return
  362.                 end
  363.                 for p,v in pairs(oldCFs) do
  364.                     p.CFrame = v:lerp(v*CFrame.Angles(0, math.rad(90), 0), i)
  365.                     if trueCFs[p] then
  366.                         trueCFs[p] = v*CFrame.Angles(0, math.rad(90), 0)
  367.                     end
  368.                 end
  369.                 RS.Heartbeat:wait()
  370.             end
  371.             isMoving[Num] = nil
  372.  
  373.             local newPartSize = newParts[1].Size
  374.             for i = 0, 1, 0.25 do
  375.                 if isRemoving[PortalP] then
  376.                     for _,v in pairs(newParts) do
  377.                         v:Destroy()
  378.                     end
  379.                     return
  380.                 end
  381.                 for _,v in pairs(newParts) do
  382.                     v.Size = newPartSize:lerp(Vector3.new(12, 0.2, 0.2), i)
  383.                     v.CFrame = trueCFs[v]
  384.                 end
  385.                 RS.Heartbeat:wait()
  386.             end
  387.  
  388.             newPartSize = newParts[1].Size
  389.             for i = 0, 1, 0.1 do
  390.                 if isRemoving[PortalP] then
  391.                     for _,v in pairs(newParts) do
  392.                         v:Destroy()
  393.                     end
  394.                     return
  395.                 end
  396.                 for _,v in pairs(newParts) do
  397.                     v.Size = newPartSize:lerp(Vector3.new(0, 0.2, 0), i)
  398.                     v.CFrame = trueCFs[v]
  399.                 end
  400.                 RS.Heartbeat:wait()
  401.             end
  402.             for _,v in pairs(newParts) do
  403.                 v:Destroy()
  404.             end
  405.             wait(5)
  406.         end
  407.     end)()
  408. end
  409.  
  410. ------------------------------------------------------------------------------------------------------------------------------------------------------
  411.  
  412. local canRun = true
  413. Mouse.KeyDown:connect(function(Key)
  414.     if canRun then
  415.         canRun = false
  416.         Key = Key:lower()
  417.         local Ok, Err = coroutine.resume(coroutine.create(function()
  418.             local Hit = Mouse.Hit
  419.             local Target = Mouse.Target
  420.             local Surface =  Mouse.TargetSurface
  421.             if Key == "e" and Hit and Target and Surface then
  422.                 if (not Model:findFirstChild(tostring(1)) or isRemoving[Model[tostring(1)]] == nil) and removePortal(tostring(1)) == false then
  423.                     makePortal(1, Hit, Target, Surface)
  424.                 end
  425.             elseif Key == "f" and Hit and Target and Surface then
  426.                 if (not Model:findFirstChild(tostring(2)) or isRemoving[Model[tostring(2)]] == nil) and removePortal(tostring(2)) == false then
  427.                     makePortal(2, Hit, Target, Surface)
  428.                 end
  429.             elseif Key == "r" and Hit and Target and Surface then
  430.                 local newNum = 1
  431.                 if LastPortalNum == 1 then
  432.                     newNum = 2
  433.                 end
  434.                 coroutine.wrap(function()
  435.                     removePortal(tostring(newNum))
  436.                 end)()
  437.                 makePortal(newNum, Hit, Target, Surface)
  438.             end
  439.         end))
  440.         if not Ok then
  441.             print("Error1:", Err)
  442.         end
  443.         canRun = true
  444.     end
  445. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement