local RS = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
local module = require(script.Parent.Parent.CharSlotV2.ModuleScript)
RS.Party.PartyEvents.Teleport.OnServerEvent:Connect(function(plr, party)
local TPid = party.TeleportId.Value
local server = TeleportService:ReserveServer(TPid)
for _, player in pairs(party.Players:GetChildren()) do
local slots = module.Get(plr)
if not slots then plr:Kick("Could not get character slots with teleporting") return end
local tpOptions = Instance.new("TeleportOptions")
for i, slot in pairs(slots) do
if slot.Equipped then
print("yo")
tpOptions:SetTeleportData({party.Difficulty.Value, i})
end
end
local teleportingPlayer = game.Players:FindFirstChild(player.Value)
TeleportService:TeleportToPrivateServer(TPid, server, {teleportingPlayer}, tpOptions)
end
end)
This is what i tried for game B
local tpOptions = Instance.new("TeleportOptions")
local data = tpOptions:GetTeleportData()
print(data, "Is data")
for i, v in pairs(data) do
print(i, "is i", v, "is v")
end
but data prints as nil
I also tried this
local joinData = plr:GetJoinData()
if joinData then
print(joinData, "is joindata")
for a, b in pairs(joinData) do
print(a, "is a", b, "is b")
if type(b) == "table" then
for l, c in pairs(b) do
print(l, "is l", c, "is c")
end
end
end
else
print("no join data")
end
In your code for Game A, you are using TeleportOptions to set teleport data for the player before teleporting to another server. In Game B, you’re trying to retrieve this data using tpOptions:GetTeleportData(), but that’s not the correct way to retrieve the data set in another game.
When you set teleport data using tpOptions:SetTeleportData() in Game A, this data is not directly accessible in Game B by simply creating a new TeleportOptions instance and calling GetTeleportData().
To pass data from Game A to Game B using TeleportService, you should use TeleportService:TeleportToPrivateServerAsync or similar methods in Game A to pass the data as a parameter when you’re requesting the teleport. Here’s how you can do it:
In Game A (Server Script):
local TeleportService = game:GetService("TeleportService")
local TPid = -- your server ID
local tpOptions = Instance.new("TeleportOptions")
-- Set teleport data in Game A
tpOptions:SetTeleportData({party.Difficulty.Value, i})
-- Teleport to the other game with the data
TeleportService:TeleportToPrivateServerAsync(TPid, "PlaceIdOfGameB", {plr}, tpOptions)
In Game B (Server Script or Local Script):
local TeleportService = game:GetService("TeleportService")
-- Inside your TeleportService event handler, you can retrieve the data as follows:
local tpOptions = game.Players.LocalPlayer:GetAttribute("TeleportOptions")
if tpOptions then
local data = tpOptions:GetTeleportData()
-- Now, 'data' contains the data you set in Game A
end
In this approach, you set the teleport data in Game A using SetTeleportData, and when you teleport to Game B, you pass this data as part of TeleportService:TeleportToPrivateServerAsync. In Game B, you can retrieve this data from game.Players.LocalPlayer:GetAttribute("TeleportOptions").
I’ll be honest I was tryna help you but I felt this was a lil too advanced for me and didn’t have an answer so i got a lil help from ai
Sorry if it made you angry or something like that
I used DataStoreService Instead and it works fine. I realised that teleportOptions would only work on client so this is the code
local RS = game:GetService("ReplicatedStorage")
local DSS = game:GetService("DataStoreService")
local EquipDS = DSS:GetDataStore("EquipDS")
local PartyDS = DSS:GetDataStore("PartyDS")
local TeleportService = game:GetService("TeleportService")
local module = require(script.Parent.Parent.CharSlotV2.ModuleScript)
RS.Party.PartyEvents.Teleport.OnServerEvent:Connect(function(plr, party)
local TPid = party.TeleportId.Value
local server, id = TeleportService:ReserveServer(TPid)
PartyDS:SetAsync(id, party.Difficulty.Value)
for _, player in pairs(party.Players:GetChildren()) do
local realPlayer = game.Players:FindFirstChild(player.Value)
local slots = module.Get(realPlayer)
if not slots then realPlayer:Kick("Could not get character slots with teleporting") return end
for i, slot in pairs(slots) do
if slot.Equipped then
EquipDS:SetAsync(realPlayer.UserId, i)
end
end
local teleportingPlayer = game.Players:FindFirstChild(player.Value)
TeleportService:TeleportToPrivateServer(TPid, server, {teleportingPlayer})
end
end)