Advertisement
KINGOFCOOL

Untitled

Jan 19th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. game:GetService("TeleportService").CustomizedTeleportUI = true
  2. button.MouseButton1Click:connect(function()
  3. -- Fire RemoteEvent
  4. game:GetService("TeleportService"):Teleport(otherPlaceId)
  5.  
  6. -- Make loading screen visible
  7. loadingScreen.Visible = true
  8.  
  9. -- Fade screen in
  10. for i = 1, 0, -.05 do
  11. loadingScreen.BackgroundTransparency = i
  12. wait()
  13. end
  14. loadingScreen.BackgroundTransparency = 0
  15. end)
  16. local teleportService = game:GetService("TeleportService")
  17. local otherPlaceId = 181522543
  18.  
  19. -- Bind function to RemoteEvent to teleport player and protect player during transit
  20. game.ReplicatedStorage.TeleportRequestEvent.OnServerEvent:connect(function(player)
  21. -- Give character force field for protection
  22. local character = player.Character
  23. local forceField = Instance.new("ForceField", character)
  24.  
  25. -- Handle rare case where teleport fails
  26. player.OnTeleport:connect(function(teleportState)
  27. if teleportState == Enum.TeleportState.Failed then
  28. game.ReplicatedStorage.TeleportRequestEvent:FireClient(player)
  29. forceField:Destroy()
  30. end
  31. end)
  32.  
  33. -- Teleport player to other place
  34. teleportService:Teleport(otherPlaceId, player)
  35. end)
  36. local screen = script.Parent
  37. local button = screen.TeleportButton
  38. local loadingScreen = screen.LoadingScreen
  39.  
  40. -- Disable default teleport gui
  41. game:GetService("TeleportService").CustomizedTeleportUI = true
  42.  
  43. -- Bind function to teleport button that request's server teleport the player
  44. button.MouseButton1Click:connect(function()
  45. -- Fire RemoteEvent
  46. game.ReplicatedStorage.TeleportRequestEvent:FireServer()
  47.  
  48. -- Make loading screen visible
  49. loadingScreen.Visible = true
  50.  
  51. -- Remove all of the core gui elements
  52. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
  53.  
  54. -- Fade screen in
  55. for i = 1, 0, -.05 do
  56. loadingScreen.BackgroundTransparency = i
  57. wait()
  58. end
  59. loadingScreen.BackgroundTransparency = 0
  60. end)
  61.  
  62. -- Bind function to RemoteEvent to turn off loading screen and reactivate CoreGui
  63. -- in case teleport doesn't work for some reason
  64. game.ReplicatedStorage.TeleportRequestEvent.OnClientEvent:connect(function()
  65. loadingScreen.Visible = false
  66. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
  67. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement