TeleportData not working

  1. What do you want to achieve? Keep it simple and clear!

I want to send a simple 5 digit code from the main game to a place within that game

  1. What is the issue?

I tried 5 diffrent things and not even one worked, the data its just not sending to the other place, it is saving on the main game (tested with prints) but not outputting on the other one

  1. What solutions have you tried so far?

I tried searching everywhere but it didn’t help

Script in the main game

local function createReservedServer(player)
	if game.ReplicatedStorage.Purchases.Value >= 1 then
		local serverCode = generate5DigitCode()

		-- Reserve a new server and get its code
		local reservedServerCode = TeleportService:ReserveServer(PLACE_ID)

		-- Store the server code in the DataStore
		local success, errorMessage = pcall(function()
			serverCodeStore:SetAsync(serverCode, reservedServerCode)
		end)

		if success then
			print("Server code saved successfully: " .. serverCode)
			updateServerCodeEvent:FireClient(player, serverCode)
			player:SetAttribute("ServerCode", serverCode)

			task.wait(1)

			-- Create TeleportOptions and set teleport data
			local teleportOptions = Instance.new("TeleportOptions")
			local teleportData = {
				code = serverCode
			}
			
			teleportOptions:SetTeleportData(teleportData)
			teleportOptions.ShouldReserveServer = true

			-- Teleport the player to their reserved server with teleport options
			TeleportService:TeleportAsync(PLACE_ID, {player}, nil, teleportOptions)
			print("Teleporting")
		else
			warn("Failed to save server code: " .. errorMessage)
		end
	end
end

And the other script in the Place:

game.Players.PlayerAdded:Connect(function(player)
	task.wait(1)
	local teleportData = player:GetJoinData()
	local TpData = teleportData.teleportData
	
	if TpData then
		print("Received server code:", TpData.code)
		game.ReplicatedStorage.Stuff.UpdateCode:FireClient(player,tostring(TpData.code))
	end
end)

Try printing the return of the Teleport function as it contains the teleport data. Also just try printing the GetJoinData().

You also might want to try using Memory Stores instead

1 Like

printing the GetJoinData() just prints out nil, so the main problem is that it dosen’t even work

Pls don’t use it. Just use ps and set it on two places :sob:

1 Like

Sorry to ask but what is ps?

char limit

There are 4 parameters being sent here:

TeleportAsync only accepts 3. The 3rd parameter should be the teleportOptions.

1 Like

Oops, my mistake, i fixed it but still dosen’t work, i really don’t know why

Found the solution, I just had to add the

task.wait(1)

Before sending the teleportAsync

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