local teleportService = game:GetService("TeleportService")
local teleportGui = script.Parent --Path to the teleport GUI
teleportService:SetTeleportGui(teleportGui)
local TeleportService = game:GetService("TeleportService")
local gameID = 11533683844
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local teleportGui = script.Parent.Parent.Parent.ServerStorage.teleporting
TeleportService:SetTeleportGui(teleportGui)
TeleportService:Teleport(gameID, player)
end
end
script.Parent.Touched:connect(onTouched)
That would work, but you really only have to use it once:
local TeleportService = game:GetService("TeleportService")
local gameID = 11533683844
local teleportGui = game.ServerStorage.teleporting
TeleportService:SetTeleportGui(teleportGui)
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:Teleport(gameID, player)
end
end
script.Parent.Touched:Connect(onTouched)
My apologies, you can only use :SetTeleportGui() on the client. I assumed it would replicate, but apparently not.
You’ll have to set up a RemoteEvent and fire it every time you teleport a player to make this work. You’ll also need to move the GUI to somewhere like ReplicatedStorage so the client can access it.
Example scripts:
Server script:
local TeleportService = game:GetService("TeleportService")
local gameID = 11533683844
local teleportEvent = game.ReplicatedStorage.Teleport --Path to the RemoteEvent
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
teleportEvent:FireClient(player)
TeleportService:Teleport(gameID, player)
end
end
script.Parent.Touched:Connect(onTouched)
Client LocalScript (located in StarterPlayerScripts):
local teleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
local teleportEvent = game.ReplicatedStorage.Teleport --Path to the RemoteEvent
local teleportGui = game.ReplicatedStorage.teleporting
teleportEvent.OnClientEvent:Connect(function()
teleportGui.Parent = playerGui --Makes the GUI appear instantly instead of having to wait a few seconds
teleportService:SetTeleportGui(teleportGui)
end)
Please note that the teleport GUI will only work when teleporting to places inside your own game, and will not work if teleporting to other games (e.g. you teleport to ‘Welcome to Bloxburg’).
Let me know if there are any more problems,
Fizzitix
Apparently there can be some delay with the RemoteEvent, and it does not change the loading screen fast enough. See if adding a delay before attempting to teleport fixes the problem:
Server script:
local TeleportService = game:GetService("TeleportService")
local gameID = 11533683844
local teleportEvent = game.ReplicatedStorage.Teleport --Path to the RemoteEvent
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
teleportEvent:FireClient(player)
task.delay(3, function()
TeleportService:Teleport(gameID, player)
end)
end
end
script.Parent.Touched:Connect(onTouched)