Teleport Data issue

When someone clicks a button to make a priv server, (teleports with priv server) the server that they teleported to got “nil”

-- local script on 2nd place
local TeleportService = game:GetService("TeleportService")

local teleportData = TeleportService:GetLocalPlayerTeleportData()

print("Local player arrived with this data:", teleportData)

--output
-- Local player arrived with this data: nil

---------------------------------
-- server script on main
local teleportService = game:GetService("TeleportService")
local targetPlaceId = 129744516877103
local globaldata = game:GetService("DataStoreService"):GetDataStore("Servers")
local players = game.Players:GetPlayers()
local servers 

function teleport()
	local thing = Instance.new("StringValue") 
	thing.Name = "Server"
	local AccessCode = teleportService:ReserveServer(targetPlaceId)
	servers = AccessCode
	local teleportdata = {
		a = AccessCode
	}
	thing.Value = servers
	thing.Parent = game.Workspace.serverkeys
	globaldata:SetAsync("Servers",servers)
	local teleportop = Instance.new("TeleportOptions")
	local data = game:GetService("HttpService"):JSONEncode(teleportdata)
	print(data)
	teleportop:SetTeleportData(data)	
	print(teleportop:GetTeleportData())

	teleportService:TeleportToPrivateServer(targetPlaceId, AccessCode, game.Players:GetPlayers(),nil,teleportop)
	print(AccessCode)
end
script.Parent.MouseButton1Click:Connect(function()
	teleport()
end)





-- yes httpservice is on

image

--also made a server script on 2nd place

game.Players.PlayerAdded:Connect(function(player)
	local join = player:GetJoinData()
	local thing1 = game:GetService("HttpService"):JSONDecode(join)
	local teleport = thing1.TeleportData
	--local thing = teleport.a
	print(teleport) -- output nil
end)
1 Like

Forgot to add, main server is a 1 player server and 2nd is 200

Why are you using :GetLocalPlayerTeleportData when the player is teleporting from the server? Use :GetJoinData instead

The last lua script on start of thread was the server sided on 2nd place

image
2nd output was

print(teleportop:GetTeleportData()) -- getting the data from 2nd place is wrong, or sending wrong

When you use TeleportOptions:SetTeleportData(), you probably should directly pass the Lua table (not JSON-encoded data) to it.

Passes this
image

and gets nil from 2nd

teleportop:SetTeleportData(teleportdata)	
Based off your script
--origin server script
local teleportService = game:GetService("TeleportService")
local targetPlaceId = 129744516877103
local globaldata = game:GetService("DataStoreService"):GetDataStore("Servers")
local players = game.Players:GetPlayers()
local servers

function teleport()
	local thing = Instance.new("StringValue") 
	thing.Name = "Server"
	local AccessCode = teleportService:ReserveServer(targetPlaceId)
	servers = AccessCode
	local teleportdata = {a=AccessCode}
	thing.Value = servers
	thing.Parent = game.Workspace.serverkeys
	globaldata:SetAsync("Servers", servers)
	local teleportop = Instance.new("TeleportOptions")
	
	teleportop:SetTeleportData(teleportdata)
	teleportService:TeleportToPrivateServer(targetPlaceId, AccessCode, game.Players:GetPlayers(), nil, teleportop)
	print(AccessCode)
end

script.Parent.MouseButton1Click:Connect(function()
	teleport()
end)


--destination client script
local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()
print("player arrived with data:", teleportData)

Actually I have never tried a private server yet. So this is a bit of quick research too.
Also untested.

Still output on 2nd nil, char limittttt
image

After ur edit it still says nil

I’d start looking around at other things.

Test scritps
--origin local script .. GUI Button
local TeleportService = game:GetService("TeleportService")
local targetPlaceId = 129744516877103

function teleportPlayers()
	local accessCode = TeleportService:ReserveServer(targetPlaceId)
	local teleportData = { AccessCode = accessCode }

	local teleportOptions = Instance.new("TeleportOptions")
	teleportOptions:SetTeleportData(teleportData)

	TeleportService:TeleportToPrivateServer(targetPlaceId, accessCode, game.Players:GetPlayers(), nil, teleportOptions)
	print("Players teleported to private server with AccessCode:", accessCode)
end

script.Parent.MouseButton1Click:Connect(teleportPlayers)


--destination local script .. StarterPlayerScripts
local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()
print("Player teleport data: ", teleportData)

if teleportData then
	for key, value in pairs(teleportData) do
		print(key, value)
	end
else
	print("No teleport data.")
end

On second server it kicks me for this.

Dev friend pranked me by a kick

Still says nil
image
Can you add me on discord? ‘cuzangaming’
I don’t want to flood this

This is out of my league… I’ve done this server to server but never to a private server. Can’t say anything with certainty. If it’s getting that far then it’s being sent or read somehow wrong… I would guess.

Alright. Thanks for helping out tho!

bump? characher limittttttttttttttttttttttttt

I think i figured it out, it may be because your sending the teleport options,

Instead I think you should just send the JSON encoded data

Try this instead:

function teleport()
	local thing = Instance.new("StringValue") 
	thing.Name = "Server"
	local AccessCode = teleportService:ReserveServer(targetPlaceId)
	servers = AccessCode
	local teleportdata = {a=AccessCode}
	thing.Value = servers
	thing.Parent = game.Workspace.serverkeys
	globaldata:SetAsync("Servers", servers)

	teleportService:TeleportToPrivateServer(targetPlaceId, AccessCode, game.Players:GetPlayers(), nil, teleportdata)
	print(AccessCode)
end
1 Like

This worked, thanks!
Char limittttttttttt

Awesome, but be cautious when using this, i wouldn’t recommend to send important data when teleporting across places as the client has access to such data and it can be spoofed.

More info here: Teleporting Between Places | Documentation - Roblox Creator Hub

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.