Advertisement
HowToRoblox

PortalHandler

May 1st, 2021
1,821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. local p1 = workspace:WaitForChild("Portal1")
  2. local p2 = workspace:WaitForChild("Portal2")
  3.  
  4. local p1Gui = script.SurfaceGuiTemplate:Clone()
  5. local p1VPF = Instance.new("ViewportFrame", p1Gui)
  6. p1VPF.Size = UDim2.new(1, 0, 1, 0)
  7. local p1Cam = Instance.new("Camera", p1VPF)
  8. p1VPF.CurrentCamera = p1Cam
  9.  
  10. local p2Gui = p1Gui:Clone()
  11. p1Gui.Parent, p2Gui.Parent = script.Parent, script.Parent
  12. p1Gui.Adornee, p2Gui.Adornee = p1, p2
  13.  
  14.  
  15. function createView()
  16.  
  17.     p1Gui.ViewportFrame:ClearAllChildren()
  18.     p2Gui.ViewportFrame:ClearAllChildren()
  19.  
  20.     local cam1 = Instance.new("Camera", p1Gui.ViewportFrame)
  21.     p1Gui.ViewportFrame.CurrentCamera = cam1
  22.     local cam2 = Instance.new("Camera", p2Gui.ViewportFrame)
  23.     p2Gui.ViewportFrame.CurrentCamera = cam2
  24.  
  25.     cam1.CFrame = p1.CFrame
  26.     cam2.CFrame = p2.CFrame
  27.  
  28.  
  29.     for i, child in pairs(workspace:GetChildren()) do
  30.  
  31.         if not child:IsA("Terrain") then
  32.             child.Archivable = true
  33.             child:Clone().Parent = p1Gui.ViewportFrame
  34.             child:Clone().Parent = p2Gui.ViewportFrame
  35.         end
  36.     end
  37. end
  38.  
  39. createView()
  40. workspace.DescendantAdded:Connect(createView)
  41. workspace.DescendantRemoving:Connect(createView)
  42.  
  43.  
  44. local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
  45.  
  46. hum.Touched:Connect(function(part)
  47.    
  48.     if part == p1 then
  49.         hum.Parent.HumanoidRootPart.CFrame = p2.TeleportPart.CFrame + Vector3.new(0, 10, 0)
  50.     elseif part == p2 then
  51.         hum.Parent.HumanoidRootPart.CFrame = p1.TeleportPart.CFrame + Vector3.new(0, 10, 0)
  52.     end
  53. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement