Unable to pass data through teleport service

You can write your topic however you want, but you need to answer these questions:

  1. I want it so when a remote event fires it will teleport the player and pass some data through as well.

  2. Whenever I try pass data through it doesn’t work

Unable to cast value to objects -- Error
  1. I’ve tried the dev hub, Roblox and Roblox studio discord server
local TPS = game:GetService("TeleportService") -- We got da teleport service

game.Players.PlayerAdded:Connect(function()
	game.ReplicatedStorage.TeleportPlayers.Event:Connect(function(player, ChosenMap)
		print("Remote event fired")
		local reservedServerCode = TPS:ReserveServer(9373052616)
		print("The private server code is "..reservedServerCode)

		print("Teleporting "..player.Name.." to the private server")
		
		local TeleportingScreen = script.Teleporting:Clone()
		TeleportingScreen.Parent = game.Players:FindFirstChild(player.Name).PlayerGui
		
		TPS:TeleportToPrivateServer(9373052616, reservedServerCode, ChosenMap, {player}) -- error line
	end)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You can’t send an object through TeleportData.

So should I do something like

TPS:TeleportToPrivateServer(9373052616, reservedServerCode, ChosenMap, player)

instead?

No. Keep the previous one, and change player to player.Name. Then, on your receiving end you will need to check for the player’s name instead.

I’ve changed it to

		TPS:TeleportToPrivateServer(9373052616, reservedServerCode, ChosenMap, {player.Name}) -- error line, same error

But I still keep getting the same error

Actually, I believe I just forgot to read the whole line. This should fix it:

TPS:TeleportToPrivateServer(reservedServerCode, {player}, nil, ChosenMap)

It’s now saying

unable to cast string to int64

and I thought the {player} needed to be {player.Name}

I think I forgot the syntax again…
The DevHub probably has a solution.
But try this for debugging.

TPS:TeleportToPrivateServer({player}, reservedServerCode)

Try this:

local TPS = game:GetService("TeleportService") -- We got da teleport service

game.Players.PlayerAdded:Connect(function()
	game.ReplicatedStorage.TeleportPlayers.Event:Connect(function(player, ChosenMap)
		print("Remote event fired")
		local reservedServerCode = TPS:ReserveServer(9373052616)
		print("The private server code is "..reservedServerCode)

		print("Teleporting "..player.Name.." to the private server")
		
		local TeleportingScreen = script.Teleporting:Clone()
		TeleportingScreen.Parent = game.Players:FindFirstChild(player.Name).PlayerGui
		
		TPS:TeleportToPrivateServer(9373052616, reservedServerCode, {player}, "ChosenMap")
	end)
end)

The syntax is:

TPS:TeleportToPrivateServer(placeID, reservedServerCode, arrayOfPlayers, spawnLocationName, teleportData, customLoadingScreen)

Give me a second I’m trying to work out the dev forum I’m new to it lol

Thank you, so your code should be:

TPS:TeleportToPrivateServer(9373052616, reservedServerCode, {player}, ChosenMap)

Oh, I thought that the spawn location name was just ChosenMap and he forgot to add quotations.
I’ll change it.

1 Like

The chosenMap is meant to be like a string which I just want to pass through to the other game

Really? I thought it was the name of a SpawnLocation.

Okay I switched my script back. It should work now.

Well sort of In server script service I have a bunch of maps and to know which map to get I was going to use a string which was the ChosenMap thing

This is a good practice, but you must put it into the teleportData parameter.

TPS:TeleportToPrivateServer(9373052616, reservedServerCode, {player}, nil, nil, {ChosenMap})

I thought we only needed to do that with tables that’s why I did it for the player

This is true, but TeleportData should be a table.