Help with TeleportData

Hello,
I need help with teleportData!
It doesn’t work.
Server Script:

local teleportService = game:GetService('TeleportService')
local code = teleportService:ReserveServer(5844872161)
game.ReplicatedStorage.TeleportTime:FireAllClients()
for _, player in pairs(game.Players:GetPlayers()) do
	local teleportData = {
		health = player.Character.Humanoid.Health,
		tools = {}
	}
	for _, tool in pairs(player.Backpack:GetChildren()) do
		table.insert(teleportData.tools,tool.Name)
	end
	for _, tool in pairs(player.Character:GetChildren()) do
		if tool:IsA('Tool') then
			table.insert(teleportData.tools,tool.Name)
		end
	end
	teleportData = game.HttpService:JSONEncode(teleportData)
	teleportService:TeleportToPrivateServer(5844872161, code, {player}, teleportData)
end

Local Script in new place:

local player = game:GetService('Players').LocalPlayer
local teleportService = game:GetService('TeleportService')
local teleportData = teleportService:GetLocalPlayerTeleportData()


if teleportData then
	teleportData = game.HttpService:JSONDecode(teleportData)
	print('Teleport Data found!')
	game.ReplicatedStorage.TeleportData:FireServer(teleportData)
else
	print('No teleport data')
end

There are no errors, No Teleport Data prints, we don’t know why!
Help is appreciated!

Without the :JSONEncode, we get this error:

image

I looked at @VegetationBush’s post. But it didn’t help!

You should directly get the teleportData from the server with player:GetJoinData(). Also there is no need to encode/decode it, just check that the data is from the right gameId and how old it is.
For that you can save tick() in the data when starting the teleport and in the private server compare it to the current tick().

Without the :JSONEncode, we get this error:

image

Did you remove also the JSONDecode? If so, show your code in the lines where the error is.

It’s the line where I do the teleporting in.

Please be patient, we will answer when we can. Which line are you having issues with, specifically? We need to know this so we can help you.

This line ^^
That’s the line that errors.

Try removing the brackets, does that fix anything?

That just causes an error because it needs to be in a table.

teleportData isn’t being returned because you are passing it under the parameter ‘spawnName’.
The parameters for TeleportToPrivateServer are placeId, reservedServerAccessCode, players, spawnName, and teleportData. Your code teleportService:TeleportToPrivateServer(5844872161, code, {player}, teleportData) passes teleportData as spawnName which is why your aren’t receiving it. To fix this just pass nil or a placeholder as spawnName. Your new code should look like teleportService:TeleportToPrivateServer(5844872161, code, {player}, _, teleportData) or
teleportService:TeleportToPrivateServer(5844872161, code, {player}, nil, teleportData)

1 Like

Take a look at this API reference: TeleportService | Documentation - Roblox Creator Hub

1 Like