TeleportData is not working

Hi, so im trying to make a system where you join another server and get teleported to a specific location when joining. While doing that im using TeleportData wich is not working in my case, here are the scripts:

Server:

Summary
game.Players.PlayerAdded:Connect(function(plr)
    print("USER HAS JOINED")
    local tp_data = plr:GetJoinData()
    if tp_data then
        print("User HAS DATA")
        print(game:GetService("HttpService"):JSONEncode(tp_data))
        local stationid = tp_data.StationID
        print(stationid)
        end
end)

Client:

Summary
local teleportOptions = Instance.new("TeleportOptions")
local data = {
     StationID = script.Parent.Main.Home.TicketSearcher.Start_Station.ID.Value,
}
teleportOptions:SetTeleportData(data)
game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId,serverInstance,player,nil,teleportOptions)

Output:

USER HAS JOINED
User HAS DATA
[]
nil

I had to encode the table so i can see it in the game console so don’t mind that.

Thank you in advance! :grinning:
Ps: This is my first post so feedback on it is greatly appreciated!

1 Like

Data is only accessible by client.
You have to use TeleportService:GetLocalPlayerTeleportData in a local script, then use remote events to transfer that data to the server.

To make it safe from exploiters, you can add keys.
And check the value from server script. (But I dont recommend you to use this way)

Since you are teleporting a player through local script, the teleport data will also be visible for client and not for server, although if you teleport the player from the server withteleport data then player:GetJoinData() might work.

@offchoci

So I tried this code:

ocal ts = game:GetService("TeleportService")

ts.LocalPlayerArrivedFromTeleport:Connect(function(gui,data)
	local d = ts:GetLocalPlayerTeleportData()
	print(game:GetService("HttpService"):JSONEncode(d))
end)

it did not work either.

It output nothing, and without the localplayerarrived event it did the same. The script is lcoated in StarterPlayerScript btw.

Have you tried teleporting player from server script instead of client?

I tried too, didnt work either.

Like, using :TeleportToPlaceInstance from a server script then
Using player:GetJoinData() from server script.

Yes and this was the code for it:

game.ReplicatedStorage.TpUserToPlace.OnServerEvent:Connect(function(plr,placeid, options)
	game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId,placeid,plr,nil,options)
end)

Didnt work either

In order for this to work, you have to call TeleportAsync from server-side with TeleportOptions argument (it can be created via Instance.new("TeleportOptions") and then you should call SetTeleportData on it before passing it to the TeleportAsync method).

From here, when the player joins another server, this server should call GetJoinData method on a Player, which will return a dictionary containing TeleportData field which is a table (there is no need to use HttpService) you passed to the SetTeleportData method of TeleportOptions.

2 Likes

Well but I wanna teleport the user to another server not to another game. Thats why I need TeleportToPlaceInstance instead of TeleportAsync.

This is what you are looking for ServerInstanceId which should be set via TeleportOptions.

Ohh the thing is you are using teleportoptions here.
Replace teleport options with data

game:GetService("TeleportService"):TeleportToPlaceInstance(game.PlaceId,serverInstance,player,nil,data)

I don’t think TeleportToPlaceInstance support teleport options, it clearly shows it needs data not the teleport options.

1 Like

Ohhh I didnt know that, thank you for pointing that out. I will rewrite the code and tell y’all how it went.

This post was meant to be replied to the post of noname, I apologise.