Unable to cast value to std::string error when teleporting with teleport data

So I’m making a game that requires players to be teleported to another place. That place in question will then load a model depending on the map the players previously chose. However, I always get this error when teleporting: “Unable to cast value to std::string” in the dev console.

Teleport Code:

teleportService:TeleportToPrivateServer(placeId, code, teleportList, {["SelectedMission"] = selectedMission})

Teleport Receiver Code (In the place to be teleported to):

local players = game:GetService("Players")
local approvedId = blahblah

players.PlayerAdded:Connect(function(player)
	local joinData = player:GetJoinData()
	
	if joinData.SourcePlaceId == approvedId then
		local teleportData = joinData.TeleportData
		if teleportData then
			script.Parent.SurfaceGui.TextLabel.Text = tostring(teleportData.SelectedMission)
		end
	end
end)

I have absolutely no idea what that error means and I haven’t had much success searching it up. Any help would be appreciated.

What is selectedMission? Could you print it?
I recommend using TeleportService:TeleportAsync() as well.

Selected mission is just an integer - in this case, it’s “1”. I read that in order to pass data through teleport data, you need to send a dictionary.

I can’t use TeleportAsync() as I need the players to be sent to their own private servers to play their levels. I don’t want people to be randomly joining their sessions.

What is the teleportList data type? Is it a table or what?

It’s a table of all the players to be teleported. This is for teleporting multiple people at once.

However, the fourth parameter is not a teleport data, it’s a SpawnName which is a string. For more info, read this

1 Like

Thanks! Looks like I just needed to read the documentation more carefully…

You can absolutely do that with TeleportAsync :thinking: