Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game:GetService("TeleportService").CustomizedTeleportUI = true
- button.MouseButton1Click:connect(function()
- -- Fire RemoteEvent
- game:GetService("TeleportService"):Teleport(otherPlaceId)
- -- Make loading screen visible
- loadingScreen.Visible = true
- -- Fade screen in
- for i = 1, 0, -.05 do
- loadingScreen.BackgroundTransparency = i
- wait()
- end
- loadingScreen.BackgroundTransparency = 0
- end)
- local teleportService = game:GetService("TeleportService")
- local otherPlaceId = 181522543
- -- Bind function to RemoteEvent to teleport player and protect player during transit
- game.ReplicatedStorage.TeleportRequestEvent.OnServerEvent:connect(function(player)
- -- Give character force field for protection
- local character = player.Character
- local forceField = Instance.new("ForceField", character)
- -- Handle rare case where teleport fails
- player.OnTeleport:connect(function(teleportState)
- if teleportState == Enum.TeleportState.Failed then
- game.ReplicatedStorage.TeleportRequestEvent:FireClient(player)
- forceField:Destroy()
- end
- end)
- -- Teleport player to other place
- teleportService:Teleport(otherPlaceId, player)
- end)
- local screen = script.Parent
- local button = screen.TeleportButton
- local loadingScreen = screen.LoadingScreen
- -- Disable default teleport gui
- game:GetService("TeleportService").CustomizedTeleportUI = true
- -- Bind function to teleport button that request's server teleport the player
- button.MouseButton1Click:connect(function()
- -- Fire RemoteEvent
- game.ReplicatedStorage.TeleportRequestEvent:FireServer()
- -- Make loading screen visible
- loadingScreen.Visible = true
- -- Remove all of the core gui elements
- game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
- -- Fade screen in
- for i = 1, 0, -.05 do
- loadingScreen.BackgroundTransparency = i
- wait()
- end
- loadingScreen.BackgroundTransparency = 0
- end)
- -- Bind function to RemoteEvent to turn off loading screen and reactivate CoreGui
- -- in case teleport doesn't work for some reason
- game.ReplicatedStorage.TeleportRequestEvent.OnClientEvent:connect(function()
- loadingScreen.Visible = false
- game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement