How to make players spawn away from each other?

How would I make the players spread apart and spawn at different spots without them spawning in each other or at the same spot?

In studio if add more spawn locations, you can move them around to where you want them to spawn.

But they have a chance to spawn at the same spot.

Have you tried team spawns locations?

Try this

local spawnLoc = game.Workspace.SpawnLocation

game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function(character)
      local HRP = character:WaitForChild("HumanoidRootPart")
      HRP.CFrame = spawnLoc.CFrame + Vector3.new(math.random(1,100), spawnLoc.Position.Y, math.random(1,100))
   end)
end)
2 Likes

You could make different teams then, make a limit of each team of one player.

This is the same as just placing around more spawn locations.

1 Like

I don’t know why I didn’t think about this. this randomly places them in a spot

1 Like

Thank you, but I don’t think theres a way to hide teams. Thats the reason why I haven’t done this.

wait does this randomly move then 1 stud?

Where would I put this script?

Serverscriptservice (30 limit)

1 Like

Actually, here is an improved script if you want players to be separated

local spawnLoc = game.Workspace.SpawnLocation
local maxPos = 1000
local minDistance = 10
local foundPos = false
local positions = {}

game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function(character)
      local HRP = character:WaitForChild("HumanoidRootPart")

      local randomPos 

      if #positions > 0 then
         repeat wait()
            randomPos = Vector3.new(math.random(1,maxPos), spawnLoc.Position.Y, math.random(1,maxPos))
   
            for i, v in pairs(positions) do
               if (v - randomPos).Magnitude < minDistance then
                  foundPos = false
               else
                  foundPos = true
               end
            until foundPos == true
         end
      else
           randomPos = Vector3.new(math.random(1,maxPos), spawnLoc.Position.Y, math.random(1,maxPos))
      end

      table.insert(positions, randomPos)
      HRP.CFrame = spawnLoc.CFrame + randomPos
   end)
end)
1 Like

Thank you, I really appreciate it!

1 Like

I think your missing some ends but im not sure where to place them. line 17 need to be closed; Maybe 13?

Whoops sorry about that, try this

local spawnLoc = game.Workspace.SpawnLocation
local maxPos = 1000
local minDistance = 10
local foundPos = false
local positions = {}

game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function(character)
      local HRP = character:WaitForChild("HumanoidRootPart")

      local randomPos 

      if #positions > 0 then
         repeat wait()
            randomPos = Vector3.new(math.random(1,maxPos), spawnLoc.Position.Y, math.random(1,maxPos))
   
            for i, v in pairs(positions) do
               if (v - randomPos).Magnitude < minDistance then
                  foundPos = false
               else
                  foundPos = true
               end
            end
         until foundPos == true
      else
         randomPos = Vector3.new(math.random(1,maxPos), spawnLoc.Position.Y, math.random(1,maxPos))
      end

      table.insert(positions, randomPos)
      HRP.CFrame = spawnLoc.CFrame + randomPos
   end)
end)
1 Like