How to make people spawn different places at the same time?

I’m trying to work on making players spawn at different places but all at the same time (since I am reserving a server for groups of players).

I’m not sure how to approach or do it, I was thinking of when the player spawns in one of the locations, i would disable it quickly so another player spawns at another location but I feel that the players would spawn at the same time making this script not reliable for me.

1 Like

Everyone should spawn in at different times, depending on their hardware.

Put a list of Instances of the spawns in a table local Spawns = { ["Spawn1"] = Instance, ["Spawn2"] = Instance }.

Whenever they spawn in, set their CFrame to a Random Instances’ Position in the table HumanoidRootPart.CFrame = Spawns[Index].Position.

Remove the Spawn Instance that they spawned on from the table table.remove(Spawns, Index).

And then do that for every player added. I believe that I worded this correctly, if some of it doesn’t make sense then it probably was just me.

local Players = game:GetService("Players")

local Spawns = {
    ["Spawn1"] = Instance,
    ["Spawn2"] = Instance,
    ["Spawn3"] = Instance,
    ["Spawn4"] = Instance
}

Players.PlayerAdded:Connect(function(Player)
     Players.CharacterAdded:Connect(function(Character)
         local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
         local Index = math.random(1, #Spawns)

         HumanoidRootPart.CFrame = Spawns[Index].Position

         table.remove(Spawns, Index)
     end)
end)
3 Likes

I would like to add that you should use a pair loop to remove the spawn each time a player spawns. As mentioned, you will remove the spawn from the ‘Spawns’ table before spawning in the next player. Idk if you can add an event that will remove the spawn from the table using the CharacterAdded event to prevent more than one player spawning in the same location, but I would loop through just to be safe.

1 Like

Although, if the player resets. They will be an error most likely because there will be no spawns. I would say to make the CharacterAdded function to Player.CharacterAdded:Once(function(Character)) if you have that issue.

For the table.remove(Spawns, Index) I’m not sure if it’s supposed to be Index or Index - 1. Might be a slight issue.

Roblox tables start at 1, so I believe just index is fine.