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!
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().
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)