Help using TeleportService to make a story game

Around a year ago, I attempted to make my first game. I tried to make a story game, which I now realize was a bad choice for a first game as I knew nothing. As you could guess, it was a major failure. I decided to come back to it a few days ago, and everything was going smooth, except for one problem.

Teleportation.

I can’t seem to figure out how they manage to send only the people in the vehicle to a new server without doing any of the following:

  1. sending them to a server already running
  2. sending them to an empty but finished server that didn’t quite shut down yet
  3. having someone join their own server

Here is my script so far. It revolves around a canoe with multiple seats that leave every 30 seconds. The script is inside of the part you touch to teleport into the canoe. The function fires when you touch the part.

local TeleportService = game:GetService("TeleportService")
local Place = --place ID

function onTouched(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		wait(0)
			TeleportService:Teleport(Place, player)
end
end
 
script.Parent.Touched:connect(onTouched)

I’ve tried using TeleportService:TeleportToPrivateServer() but that doesn’t work. Then I thought that it might have to do with TeleportService:ReserveServer(). I couldn’t figure that out as all that gave me was a variety of errors. The game server is in another place inside the game and the lobby is the main place/spawn place. If I can’t figure this out, I’m going to adapt it to be a 1-player story game.

I bet the answer is so obvious and I just didn’t realize it.

I do know how to make sure the players in the canoe teleport at the same time, I just haven’t added it yet. I just don’t know how to teleport them to their own server.

4 Likes

use TeleportService:ReserveServer(placeId) and TeleportService:TeleportToPrivateServer(placeId, code, players) to create and teleport to a private server.

ReserveServer gives u a code that u can put into TeleportToPrivateServer to teleport to a private server.

TeleportToPrivateServer needs a placeId the code and a table of players to teleport.

[TeleportService Documentation]

Also. Use :Connect instead of :connect

7 Likes

the lowercase c is a typo, sorry.

but how would you get the code from reserveServer? by using reserveserver as a variable?
local code = TeleportService:ReserveServer()

would that work?

1 Like

Yes. ReserveServer returns the code.

3 Likes

Ah, I see. That’s very helpful. I’m not very familiar with TeleportService.

3 Likes