Help with making a teleporting script

Hello fellow developers ! I want to make a type of teleporting service for my game in which like first all the players spawn in a lobby and then I want to create two parts upon touching them , the player will teleport to a different game where that specific game mode can be played. Some examples of the system I want are the mimic game teleport system and YBA metal ball run teleport system. I will really appreciate any help I receive.

1 Like

Ok so you’re gonna need to add the extra places to your game in the asset manager. After that I recommend using TeleportService | Roblox Creator Documentation. It will also help if you read Teleporting Between Places | Roblox Creator Documentation, specifically the “Teleport on Part Touch” section.

2 Likes

Well, first of all, you can research the information you need. You can find out more information about teleporting to places here: Teleporting Between Places | Roblox Creator Documentation.

If you want to detect if part is touched, you can do

-- Example Code for 'Touched' Event
part.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(hit.Parent.Name) then
      -- Teleport Code Here
   end
end)

Here is the full code if you want to be spoonfed:


Module Script (Put inside ReplicatedStorage)

local TeleportService = game:GetService("TeleportService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local TeleportModule = {}
 
local RETRY_DELAY = 2
local MAX_WAIT = 10
 
-- Create remote event instance
local teleportEvent = Instance.new("RemoteEvent")
teleportEvent.Name = "TeleportEvent"
teleportEvent.Parent = ReplicatedStorage
 
function TeleportModule.teleportWithRetry(targetPlaceID, playersTable, teleportOptions)
	local currentWait = 0
 
	-- Show custom teleport screen to valid players if client event is connected
	teleportEvent:FireAllClients(playersTable, true)
 
	local function doTeleport(players, options)
		if currentWait < MAX_WAIT then
			local success, errorMessage = pcall(function()
				return TeleportService:TeleportAsync(targetPlaceID, players, options)
			end)
			if not success then
				warn(errorMessage)
				-- Retry teleport after defined delay
				wait(RETRY_DELAY)
				currentWait = currentWait + RETRY_DELAY
				doTeleport(players, teleportOptions)
			end
		else
			-- On failure, hide custom teleport screen for remaining valid players
			teleportEvent:FireAllClients(players, false)
			return true
		end
	end
 
	TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
		if teleportResult ~= Enum.TeleportResult.Success then
			warn(errorMessage)
			-- Retry teleport after defined delay
			wait(RETRY_DELAY)
			currentWait = currentWait + RETRY_DELAY
			doTeleport({player}, teleportOptions)
		end
	end)
 
	-- Fire initial teleport
	doTeleport(playersTable, teleportOptions)
end
 
return TeleportModule

Script (Put inside the teleport part)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local teleportPart = script.Parent

local targetPlaceID = 6074153281 -- Change this to your place ID

local TeleportModule = require(ReplicatedStorage:WaitForChild("TeleportModule"))

teleportPart.Touched:Connect(function(otherPart)
   local player = Players:GetPlayerFromCharacter(otherPart.Parent)
   if player and not player:GetAttribute("Teleporting") then
      player:SetAttribute("Teleporting", true)
      local teleportResult = TeleportModule.teleportWithRetry(targetPlaceID, {player})
      player:SetAttribute("Teleporting", nil)
   end
end

Please mark this as “Solution” if it worked for you, thanks!

3 Likes

Thank you so much. I really don’t want to be spoon-fed so first I will research from the links you provided and try to do on my own which I will fail and then use your code. :grinning: :+1:

3 Likes