So, I’m trying to use TeleportService in my game. Since I’m a novice, I decided to train myself first before scripting the real deal.
I’ve managed to send teleportData from the server to the reserved server. In the reserved server, I wrote this sample code:
local Players = game:GetService("Players")
local function playerAdded(player)
local joinData = player:GetJoinData()
print(joinData.TeleportData)
end
Players.PlayerAdded:Connect(playerAdded)
However, when I ran it, the output was just gibberish—random numbers and letters. Does this mean it worked? If so, how do I use the data properly?
Heya!
(Assuming you’re sending the data correctly) there are no errors with your code!
The reason it’s printing some random gibberish, is because it’s a table based on what you send as data! If you need any more help, I could try to if you send the data you sent!
local function teleport(fullyRegistered)
local playerTable = {} -- Create an array for players
local teleportData = {} -- Dictionary to send player seating info
for userId, data in pairs(fullyRegistered) do
local player = game.Players:GetPlayerByUserId(userId) -- Get Player instance
if player then
table.insert(playerTable, player) -- Insert into teleport list
-- Find the seat the player is sitting on
local char = player.Character
if char then
local humanoid = char:FindFirstChild("Humanoid")
if humanoid and humanoid.SeatPart then
teleportData[userId] = {
seatName = humanoid.SeatPart.Name, -- Store seat name
registrationNumber = data.registrationNumber -- Store registration number
}
end
end
end
end
print("Teleport Data:", teleportData) -- Debugging
--Check if there are players to teleport
if #playerTable > 0 then
teleportService:TeleportToPrivateServer(128122330564874, accessCode, playerTable, nil, teleportData)
else
warn("No players to teleport!")
end
end
what it printed in reserveServer
table: 0x35f0102cc6b08b82
but it change everytime i test it
well i attempt to fix it using this :
local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")
local function playerAdded(player)
local teleportData = player:GetJoinData().TeleportData
local HttpService = game:GetService("HttpService") -- Required for JSON encoding
local formattedData = HttpService:JSONEncode(teleportData) -- Convert table to JSON string
print(formattedData)
end
Players.PlayerAdded:Connect(playerAdded)
Tables are references in Luau, in the sense that they don’t behave the same way other data types do. In Studio, tables are automatically outputted in such a format that you can easily see the elements. In Roblox, they are outputted rawly; that output is saying it’s a table and it’s at memory location 35f0102cc6b08b82 (which is in hexadecimal). It looks like it should work from a glance.
Also, TeleportToPrivateServer should not be used for new work, according to the docs. You should use TeleportAsync with a TeleportOptions instance.
local options = Instance.new("TeleportOptions")
options.ReservedServerAccessCode = accessCode
options:SetTeleportData(teleportData)
--use a pcall for this bit
TeleportService:TeleportAsync(128122330564874, playerTable, options)
Are you decoding the table on your side after getting the data? I’ve noticed you’re encoding the data, but not decoding it (unless you didn’t show the full script)
I didn’t encode the data myself, so I assumed it would stay as a normal table. Do I need to manually decode it when the player joins? If so, how would I do that? Also, that’s the enitre script, besides the whole activate the function part
Thanks for the advice! I switched to TeleportAsync with TeleportOptions, but I’m still seeing the teleport data as gibberish. I think the issue might be on the receiving end. Do I need to decode it manually when the player joins?
You get table: 0x35f0102cc6b08b82 this because roblox displays the tables id for the developer console and not the actual table. You can either encode it into JSON or loop through the table printing things.
@iicloudsforeveriii is right. Just as I said before, in Roblox game servers, tables will be outputted as table: followed by their memory location. If you don’t want to iterate and output, you can use the __tostring metamethod, but it’s a bit tedious.
Oh, no. Not the tostring function. The __tostring metamethod is different - it controls what’s returned when you attempt to cast the table to a string.
local tbl = {}
setmetatable(tbl, {__tostring = function()
return "hi"
end})
print(tbl) --> hi
In this example, we are saying that whenever we want to cast the table to a string, it should return “hi” instead. It’s a bit tedious here, but it still could work.
It prints like that because it’s JavaScript Object Notation… because you encoded it to that on the new server. The table will output differently in Roblox game servers to how it would in Studio, but the table contents is still the same. Just treat it how you expect it to be without encoding it at all.
Oh, I understand. Well, as 12345koip suggested. You need to decode the data using HTTPService. Specifically, HTTPService:JSONDecode(data) where data is the data your received from the GetJoinData method.