How can I make players spawn at specific areas of the map?

I’m creating a script that is server sided, which creates a round and inserts a map into the workspace. The map includes a spawns folder, where I keep all my spawn parts (not real spawns), so I can move players to each part via HumanoidRootPart.

For the round specific code, I inserted both the players and the children within the map’s spawn folder into their own tables. An example of the tables and how I inserted into them is below. What I’m trying to figure out is to not have players spawn at the same part.

How do I go about this? Any help would be appreciated.

local PlayersTable = {}
local SpawnsTable = {}

for i,v in pairs(game:GetService(“Players”):GetPlayers()) do

for i,v in pairs(game.Workspace.Map.Spawns:GetChildren()) do


GetPlayers() already gets a table of players. No need to iterate and populate it in another… And neither should GetChildren(). Just update then with PlayersTable = game:GetService(“Players”):GetPlayers() for each round and SpawnsTable = workspace.Map.Spawns:GetChildren() for each new map loaded.

Iterate through PlayersTable, then index Player.Character and probably use Model:SetPrimaryPartCFrame() method(or just move the HumanoidRootPart through CFraming). Choosing a spawn requires math.random(#SpawnsTable), and indexing it in SpawnsTable. Resulting in SpawnsTable[#SpawnsTable]. For this spawn, get its position and generate a CFrame out of it, or copy its CFrame and add some Y coordinate to spawn above it.

Oh okay then. The last thing I need help with is when a spawn is chosen using math.random(), how do I remove that spawn from the table so that it is no longer possible for another player to choose that spawn?

Create a variable of just that number from math.random(#SpawnsTable), let it be randomSpawnIndex. table.remove(SpawnsTable, randomSpawnIndex) should do the trick.

1 Like

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