Teleport data sometimes sends players with another players data

Basically, when teleporting players to the next place, sometimes it sends a player with another player’s data. They end up with the same character, same skin, same team. This causes 6 v 4s on a 5 v 5 game.

while true do
local ServerCode = game:GetService(“TeleportService”):ReserveServer(11132423100)
local players = {}

local children = game.Players:GetChildren()

local worked, errorData = pcall(function()
for i = 1, #children do
local plr = children[i]
table.insert(players , plr)
local data = {
CharacterValue = plr.PlayerGui.Play.Frame.CharacterValue.Value,
PlayerTeam = plr.PlayerGui.Play.Frame.SelectedTeam.Value,
PlayerSkin = plr.PlayerGui.Play.Frame.SelectedSkin.Value
}
wait(2.5)
game:GetService(“TeleportService”):TeleportToPrivateServer(11132423100, ServerCode, players, nil, data)
end
end)
wait(45)
end

This is happening because in your loop, you aren’t indexing for a certain players data and every-time it runs it resets to the next player.

You need to make a dictionary for the data. Once the players join the private server you just need to comb through the initial keys to access each players data.

You don’t need a for i = 1, number do loop, you can localize adding the player from the loop below. Just add table.insert(players, Plr) instead of indexing from the children table then inserting.

local data = {}

for index, Plr in pairs(game.Players:GetPlayers()) do
     — Add here
     table.insert(data, Plr.Name) 
     data[Plr.Name] = {
          CharacterValue = Plr.PlayerGui.Play.Frame.CharacterValue.Value,
          PlayerTeam = Plr.PlayerGui.Play.Frame.SelectedTeam.Value,
          PlayerSkin = Plr.PlayerGui.Play.Frame.SelectedSkin.Value
     }
end
2 Likes

Hey, I managed to make it send the data. I have a local script that needs to grab the specific data of the player. I used:

player = game.Players.LocalPlayer
local tService = game:GetService(“TeleportService”)
local data = tService:GetLocalPlayerTeleportData()

if data then
local CharacterValues = data.CharacterValue
local PlayerTeams = data.PlayerTeam
local SkinValues = data.PlayerSkin
script.Parent:FireServer(CharacterValues,PlayerTeams,SkinValues)
end

It still does the same thing for now because I think it doesn’t PICK the specific player data. I’ve been struggling for a while, could you help please?

Print out the data that’s been sent and copy&paste what it’s printing.

Hey, could we move to twitter? I sent you a dm there so maybe it will be easier to communicate. If you’re okay with it

prints

Okay, it now sends the data. The data has my name in it. I just don’t know how to access the values inside it now.

player = game.Players.LocalPlayer
local tService = game:GetService(“TeleportService”)
local data = tService:GetLocalPlayerTeleportData()
local dataowner = unpack(data)
local playername = player.Name

if data and dataowner == playername then
–I manage to get it up to this point. I don’t know how to access these three values inside.
local CharacterValues = ???
local PlayerTeams = ???
local SkinValues = ???
script.Parent:FireServer(CharacterValues,PlayerTeams,SkinValues)
end

If I print data it gives out a hex code. If I do it with unpack(data) though, it gives my name.

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