I've been at it for 2 days and I simply can't find an adequate solution: I would like to teleport the players, to certain locations, one by one.
The context is a minigame game. I want it to end up something like this: Player 1 is teleported to Location 1, Player 2 is teleported to Location 2, etc.
Also, related to the question, is this possible: -> Get number of players -> Divide by 3 -> First 3 get teleported to Location 1 -> Remaining 3 get teleported to Location 2
Help would really be appreciated! Please and Thanks!
You can use a table for spawn positions and then teleport each player according to the position in the table like:
local spawnPosition = {spawn1.Position,spawn2.Position, spawn3.Position} for i, player in ipairs(game.Players:GetChildren()) do if player.Character and player.Character:FindFirstChild("Torso") then player.Character.Torso.CFrame = spawnPosition[i] + Vector3.new(0, i * 5, 0) end end
To teleport more than one player
local spawnPosition = {spawn1.Position,spawn2.Position, spawn3.Position} plrInSpawn = 0 for i, player in ipairs(game.Players:GetChildren()) do if player.Character and player.Character:FindFirstChild("Torso") then if plrInSpawn == 3 then spawn = spawn+1 if spawnPositions[spawn] == nil then spawn = 1 end end player.Character.Torso.CFrame = spawnPosition[spawn] + Vector3.new(0, i * 5, 0) end end
Note: The codes are not tested so they may produce an error. If they do then please mention it in the comments
Thanks WInterAlien!
Your answer helped me figure out an alternative that is much more easier for me:
spawn1 = game.Workspace.spawn1 spawn2 = game.Workspace.spawn2 spawn3 = game.Workspace.spawn3 local spawnPositions = {spawn1.Position,spawn2.Position, spawn3.Position} for i, Plrs in pairs(game.Players:GetChildren()) do --Teleporting all the scrubs to the start. Plrs.Character.Torso.CFrame = CFrame.new(spawnPositions[i] + Vector3.new(0, 10, 0)) end
Thanks again!