Advertisement
Guest User

TP

a guest
Dec 31st, 2016
1,495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. -- LocalScript for Lobby place
  2.  
  3. -- Declare local variables for ROBLOX Services
  4. local TeleportService = game:GetService('TeleportService')
  5. local UserInputService = game:GetService('UserInputService')
  6. local StarterGui = game.StarterGui
  7.  
  8. -- Declare local variables
  9. local player = game.Players.LocalPlayer
  10. local otherPlaceId = 277345328
  11. local forceField = Instance.new('ForceField')
  12. local teleportButton = script.Parent
  13.  
  14. -- Create loading screen to fade in and pass with teleport function
  15. local loadingScreen = Instance.new('ScreenGui', player.PlayerGui)
  16. local loadingScreenFrame = Instance.new('Frame', loadingScreen)
  17. loadingScreenFrame.Name = 'loadingScreenFrame'
  18. loadingScreenFrame.BackgroundColor3 = Color3.new(0,0,0)
  19. loadingScreenFrame.Size = UDim2.new(1,0,1,50)
  20. loadingScreenFrame.Position = UDim2.new(0,0,0,-50)
  21. loadingScreenFrame.Visible = false
  22.  
  23. -- Hide default teleport GUI elements
  24. TeleportService.CustomizedTeleportUI = true
  25.  
  26. -- Bind function to OnTeleport in case teleport fails
  27. player.OnTeleport:connect(function(teleportState)
  28. if teleportState == Enum.TeleportState.Failed then
  29. -- Disable force field
  30. forceField.Parent = nil
  31.  
  32. -- Hide teleport GUI and show teleport button
  33. loadingScreenFrame.BackgroundTransparency = 1
  34. loadingScreenFrame.Visible = false
  35. teleportButton.Visible = true
  36.  
  37. -- Show Core GUI elements and mouse cursor
  38. StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
  39. UserInputService.MouseIconEnabled = true
  40. end
  41. end)
  42.  
  43. -- Bind function to GUI button
  44. teleportButton.MouseButton1Click:connect(function()
  45. -- Hide button, Core GUI, and mouse
  46. teleportButton.Visible = false
  47. StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
  48. UserInputService.MouseIconEnabled = false
  49.  
  50. -- Activate force field to protect player during teleport
  51. forceField.Parent = player.Character
  52.  
  53. -- Show loading screen and fade it in
  54. loadingScreenFrame.Visible = true
  55. for i = 1, 0, -.05 do
  56. loadingScreenFrame.BackgroundTransparency = i
  57. wait()
  58. end
  59. loadingScreenFrame.BackgroundTransparency = 0
  60.  
  61. -- Teleport player and pass the loading screen
  62. TeleportService:Teleport(otherPlaceId, player, nil, loadingScreen)
  63. end)
  64.  
  65. -- Local script in other place
  66.  
  67. -- Declare local variables for ROBLOX Services
  68. local TeleportService = game:GetService('TeleportService')
  69. local UserInputService = game:GetService('UserInputService')
  70. local StarterGui = game.StarterGui
  71.  
  72. -- Hide Core GUI and mouse
  73. StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
  74. UserInputService.MouseIconEnabled = false
  75.  
  76. -- Bind function to teleport arrival
  77. TeleportService.LocalPlayerArrivedFromTeleport:connect(function(loadingGui, data)
  78. -- Pause briefly to allow level to load
  79. wait(2)
  80.  
  81. -- Fade out loading screen
  82. for i = 0, 1, .05 do
  83. loadingGui.loadingScreenFrame.BackgroundTransparency = i
  84. wait()
  85. end
  86. loadingGui.loadingScreenFrame.BackgroundTransparency = 1
  87.  
  88. -- Show Core GUI and mouse
  89. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
  90. UserInputService.MouseIconEnabled = true
  91. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement