Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LocalScript for Lobby place
- -- Declare local variables for ROBLOX Services
- local TeleportService = game:GetService('TeleportService')
- local UserInputService = game:GetService('UserInputService')
- local StarterGui = game.StarterGui
- -- Declare local variables
- local player = game.Players.LocalPlayer
- local otherPlaceId = 277345328
- local forceField = Instance.new('ForceField')
- local teleportButton = script.Parent
- -- Create loading screen to fade in and pass with teleport function
- local loadingScreen = Instance.new('ScreenGui', player.PlayerGui)
- local loadingScreenFrame = Instance.new('Frame', loadingScreen)
- loadingScreenFrame.Name = 'loadingScreenFrame'
- loadingScreenFrame.BackgroundColor3 = Color3.new(0,0,0)
- loadingScreenFrame.Size = UDim2.new(1,0,1,50)
- loadingScreenFrame.Position = UDim2.new(0,0,0,-50)
- loadingScreenFrame.Visible = false
- -- Hide default teleport GUI elements
- TeleportService.CustomizedTeleportUI = true
- -- Bind function to OnTeleport in case teleport fails
- player.OnTeleport:connect(function(teleportState)
- if teleportState == Enum.TeleportState.Failed then
- -- Disable force field
- forceField.Parent = nil
- -- Hide teleport GUI and show teleport button
- loadingScreenFrame.BackgroundTransparency = 1
- loadingScreenFrame.Visible = false
- teleportButton.Visible = true
- -- Show Core GUI elements and mouse cursor
- StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
- UserInputService.MouseIconEnabled = true
- end
- end)
- -- Bind function to GUI button
- teleportButton.MouseButton1Click:connect(function()
- -- Hide button, Core GUI, and mouse
- teleportButton.Visible = false
- StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
- UserInputService.MouseIconEnabled = false
- -- Activate force field to protect player during teleport
- forceField.Parent = player.Character
- -- Show loading screen and fade it in
- loadingScreenFrame.Visible = true
- for i = 1, 0, -.05 do
- loadingScreenFrame.BackgroundTransparency = i
- wait()
- end
- loadingScreenFrame.BackgroundTransparency = 0
- -- Teleport player and pass the loading screen
- TeleportService:Teleport(otherPlaceId, player, nil, loadingScreen)
- end)
- -- Local script in other place
- -- Declare local variables for ROBLOX Services
- local TeleportService = game:GetService('TeleportService')
- local UserInputService = game:GetService('UserInputService')
- local StarterGui = game.StarterGui
- -- Hide Core GUI and mouse
- StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
- UserInputService.MouseIconEnabled = false
- -- Bind function to teleport arrival
- TeleportService.LocalPlayerArrivedFromTeleport:connect(function(loadingGui, data)
- -- Pause briefly to allow level to load
- wait(2)
- -- Fade out loading screen
- for i = 0, 1, .05 do
- loadingGui.loadingScreenFrame.BackgroundTransparency = i
- wait()
- end
- loadingGui.loadingScreenFrame.BackgroundTransparency = 1
- -- Show Core GUI and mouse
- game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
- UserInputService.MouseIconEnabled = true
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement