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))
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
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.