I’m trying to make it that when a player touches a part they teleport to a different game altogether but whenever I try doing this it always says teleport failed. Here is my code:
local TeleportService = game:GetService("TeleportService")
local gameID = 9424926656
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:Teleport(gameID, player)
end
end
script.Parent.Touched:connect(onTouched)
As a quick note, you should probably use Roblox’s SafeTeleport module. It makes teleports retry if they are failed, for a certain amount of times. (in addition to some other things, this is the main one I noticed)
function Teleport(Place)
local Success = pcall(function()
TeleportService:Teleport(Place, Player)
end)
if Success then
return
else
task.wait(.5)
Teleport(Place)
end
end
Teleport("Your Id")
You might want to apply some additional code so your code doesn’t try to teleport the player, even if it keeps failing, as this could be a bug with Roblox’s servers or the client’s internet. We don’t want to keep retrying if the teleport fails over and over without success.