TeleportService - Teleport Task does not transfer data

  1. What do you want to achieve?
    Teleport a player and data from a game to another using TeleportService.

  2. What is the issue?
    Everytime i try to teleport a player and data in the same time the data does not come along with the player.

  3. What solutions have you tried so far?
    Until now i have tried to use Teleport() and TeleportAsync() as well as SetTeleportSetting()

Here is some part of the different things i tried

-- Using Teleport()
local FinalTable = {}
local Data = {
	{1, true},
	{2, 'Test'}
} -- this is just a test Table
table.sort(tbl, function(a, b) return a[1] < b[1] end)
for _,v in ipairs(tbl) do 
	table.insert(FinalTable,v[2]) 
end -- Dont mind this, it's just to maintain the right order.. (mind the 'FinalTable' tho)

local TeleportService = game:GetService('TeleportService')
TeleportService:Teleport(PlaceId,Player,FinalTable)

-- On the other game here is the code to receive the Teleported data (LocalScript)
local TeleportedData = game:GetService('TeleportService'):GetLocalPlayerTeleportData()
if TeleportedData [1] == true then
Print(TeleportedData[2]) -- this should print 'Test'
end
-- Using TeleportAsync() 
-- Well same code but we  remplaced 'TeleportService:Teleport(PlaceId,Player,FinalTable)' with 'TeleportService:TeleportAsync(PlaceId,{Player},FinalTable)'
-- Using SetTeleportSetting()
local Data = {
	BooleanValue = true,
	ToPrintValue = 'Test'
} -- this is just a test Table
local TeleportService = game:GetService('TeleportService')
TeleportService:SetTeleportSetting('Boolean', Data.BooleanValue)
TeleportService:SetTeleportSetting('Print', Data.ToPrintValue)
wait(.1)
TeleportService:Teleport(PlaceId,Player) -- not 100% sure how TeleportSetting works idk if it requires a third argument here...

-- On the other game here is the code to receive the Teleported data (LocalScript)
local TeleportService = game:GetService('TeleportService')
if TeleportService:GetTeleportSetting('Boolean') == true then
Print(TeleportService:GetTeleportSetting('Print')) -- this should print 'Test'
end

I canā€™t get to know why it doesnā€™t work and even when iā€™m using Pcall(), it return success as if nothing wrong was happening itā€™s just ignoring the 3rd Argument of the Teleport which is the TeleportData and as for SetTeleportSetting()/GetTeleportSetting() same goes for it, itā€™s like it was being ignoredā€¦ (i may be blind and have done a big mistake that i didnā€™t notice . If it is the case please tell me :slight_smile: )

Where is the script located? Iā€™ve come across this issue before myself. You should put the local script in ReplicatedFirst (so itā€™s prioritized / is run first) because for some reason if you donā€™t prioritize TeleportService:GetLocalPlayerTeleportData(), the data doesnā€™t persist.

So the first 2 lines should be like so:

-- This should be in ReplicatedFirst
local TeleportService = game:GetService(ā€œTeleportServiceā€)
local Data = TeleportService:GetLocalPlayerTeleportData()
-- Rest of your code

If you need any clarification Iā€™ll be happy to simply it for you.

1 Like

Well, it was located in StarterPlayerScripts so i tried to change in to ReplicatedFirst as you said but it still does not persistā€¦ The problem has to be an error in my code since i tried to make Two different games with some default Teleport scripts with random teleport data just to test and they were working so the problem can only come from : The table ā€˜FinalTableā€™ (oh btw i just noticed a little error : ā€œfor _,v in ipairs(tbl) doā€ need to be remplaced with ā€œfor _,v in ipairs(Data) doā€. In my game the Table Data is named "tbl instead of ā€œDataā€.)ā€¦ but i do have noticed smthg elseā€¦ when i try the code from a LocalScript it returns ā€˜Unable to cast Value to Objectā€™ eventually this error is being ignored on the server sided script and so the Data not sent ??? i just donā€™t know and i think i will end up remaking my entire code in the end :weary:

Could you show the line that errored?

Also sorry for the late response, I was asleep cuz it was 2AM for me.

Also, you could use a Global DataStore to store data and fetch it on the other end. This is kind of a last resort.