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!
Ps: This is my first post so feedback on it is greatly appreciated!
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.
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.