One player per spawn

Hi! So I am trying to make a thing in my script that only allows one player per spawn instead of multiple. Here is what I am working with:

local players = game.Players:GetChildren()

	for i = 1, #players do
		local randomizedNumber = math.random(1,6)
		players[i].Character.Head.CFrame = CFrame.new(game.workspace.GameSystem.Teleports["Part"..randomizedNumber].Position)
		players[i].Character.Parent = game.Workspace.GameSystem.playersIngame

	end

Unfortunately, I am not that familiar with tables which is probably what I need to use in this script. I tried using bool values inside of each spawn part and checking if that value is true or not but it doesn’t work. Do you mind helping me?

1 Like

I believe repeating until not spawned on would work.

local players = game.Players:GetChildren()
local used = {}
	for i = 1, #players do
		local randomizedNumber 
		repeat
			randomizedNumber = math.random(1,6)
		until not table.find(used, randomizedNumber)
		players[i].Character.Head.CFrame = CFrame.new(game.workspace.GameSystem.Teleports["Part"..randomizedNumber].Position)
		players[i].Character.Parent = game.Workspace.GameSystem.playersIngame
		table.insert(used, randomizedNumber)
	end

Also, if there are more than 6 players this will have problems spawning all.

1 Like