Moving/teleporting players to multiple teleport parts

I’m trying to make a script that will teleport players to multiple different parts when the game begins.
When I run the game it doesn’t work, can anyone help me find a solution? (incase this is important the maps are clone from replicated storage from a folder, each map has its own folder for its teleport parts.)

local SpawnPoints = game.Workspace:GetChildren()
	local spawns = SpawnPoints.Teleports.TeleportLocation.Position
	
	local teleport = game.Players:GetChildren()
	for i = 1, #teleport do
		teleport[i].Character:MoveTo(Vector3.new(spawns.X, spawns.Y, spawns.Z))
1 Like

SpawnPoints is a table, hence , the second line won’t run.

You can get a random spawn from that table and then teleport the players to there.

local SpawnPoints = game.Workspace:GetChildren()
local spawns = SpawnPoints[math.random(1,#SpawnPoints)]
local Players = game:GetService("Players"):GetPlayers()

for _,Player in pairs(Players) do
     local Char = Player.Char or Player.CharacterAdded:Wait()
     Char:PivotTo(spawns.CFrame)
end

Hasn’t worked, I keep getting errors similar to this

 CFrame is not a valid member of Model "Workspace.Player2"

This is prob because you need to have those spawns in a folder and then access that folder and do :GetChildren(), instead of workspace

do you mind explaining how I could access that folder, I’m a bit new.


local SpawnPoints = game.Workspace.SpawnPoints:GetChildren()
local spawns = SpawnPoints[math.random(1,#SpawnPoints)]
local Players = game:GetService("Players"):GetPlayers()

for _,Player in pairs(Players) do
     local Char = Player.Char or Player.CharacterAdded:Wait()
     Char:PivotTo(spawns.CFrame)
end

Have a folder named SpawnPoints and put there your spawns.

How do I check for a folder inside of a cloned model? This is for multiple maps.

You can have that folder inside each map.
And make sure you have got a map, after that

Access that folder from the map clone

finally got it working, thank you.

1 Like