Player spawns in my game

so i want players to spawn evenly around the map through invisible, noncolliding, and anchored parts. however, the script chooses one part and teleports everyone there instead of spawning them apart from each other. how can i modify the script to allow for the script to choose a random spawn for each player?

the lines in question:


	local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
	local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
	local RandomSpawn = Spawns[math.random(1, #Spawns)]```

where exactly are you teleporting them(in the code)? move it into that function.

this is the entire script for my round system:

ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")

Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
Status = ReplicatedStorage:WaitForChild('Status')

local tool = game.ReplicatedStorage.Tools.Fists

while true do

	--Intermission

	local Countdown = 1 -- ten second intermission, make this as long as you want

	repeat wait(1)
		Countdown = Countdown - 1

		Status.Value = 'Intermission : '..Countdown
	until Countdown <= 0

	--Choose the map.

	Status.Value = 'Choosing map..'

	local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
	local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
	local RandomSpawn = Spawns[math.random(1, #Spawns)]

	wait(1) -- little pause, make this as long as you want

	ChosenMap.Parent = workspace
	Status.Value = 'Teleporting players..'

	wait(1) -- little pause, make this as long as you want

	--teleport the players
	

	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
			
			local function GiveTool(player)
				local clone = tool:Clone()
				clone.Parent = Player.Backpack
			end
			GiveTool(Player)
		end
	end

	Countdown = 1 -- Starting Round In, make this as long as you want

	repeat wait(1)
		Countdown = Countdown - 1

		Status.Value = 'Starting Round in : '..Countdown
	until Countdown <= 0

	Countdown = 10 -- Game Time, ten seconds so the video isn't long, make this as long as you want.

	repeat wait(1)
		Countdown = Countdown - 1

		Status.Value = 'Game in progress : '..Countdown
	until Countdown <= 0

	--Kill the players

	for _, Player in pairs(Players:GetChildren())do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			Player.Character.Humanoid:TakeDamage(9999999999)
		end
	end

	ChosenMap:Destroy()

	Status.Value = 'Round over!'

	wait(1) -- little pause, make this as long as you want.

end```

put the

local RandomSpawn = Spawns[math.random(1, #spawns)]

into the loop

2 Likes

thank you so much it works now