Trying to make 1 player teleport to 1 part

  1. I’m trying to make it where 1 player (randomly chosen) are teleported to one part (that’s also randomly chosen). Max players in the game are 20 players, therefore I have 20 parts all in one folder in Workspace, however, I tried to do a script but each player gets teleported onto the same part.

  2. image https://i.gyazo.com/bf23e8a77e22c25bcd1251c92d3ff0e5.mp4

I know I need to add a math.random somewhere in Players, but how do I go about it? Cause I want 1 player on 1 separate part, I don’t want 2 players on the same exact spot.


local function TeleportPlayers()
     local spawns = workspace.TeleportationPads:GetChildren()

     local availableSpawns = {}

     for i, v in pairs(spawns) do
          table.insert(availableSpawns, v)
     end

     for i, player in pairs(game.Players:GetChildren()) do
          local chosenNumber = math.random(1, #availableSpawns)
          player.Character.HumanoidRootPart.Position = availableSpawns[chosenNumber].Position
          table.remove(availableSpawns, chosenNumber)
     end
end
1 Like

Thank you, the script worked. Thanks for the help. : )

1 Like