Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can you help me with a team divider script? Its not working properly.

I am making a Team dividing script that will divide random players in the game into two teams then teleport on their pads. The problem is i cant make them to desperate evenly and one team wont spawn at their pad. Can you help me? Thanks!

Script:

local participants = {}
local Allies = {}
local Axis = {}
local h = Instance.new("Hint")

while true do wait()
	if game.Players.NumPlayers < 2 then
		local h2 = h:Clone()
		h2.Parent = game.Workspace
		h2.Text = "Need 1 More Player to Play!"
		wait(1)
		h2:Destroy()
		wait(1)
	elseif game.Players.NumPlayers >= 2 then
		break
		end
	end

--Game

for i,v in pairs(game.Players:GetChildren()) do
	table.insert(participants,v)
end

print(unpack(participants))

for i,v in pairs(participants) do
	for i = 1,#participants/2 do
		table.insert(Allies,v)
		table.remove(participants,i)
		v.Character.Torso.CFrame = game.Workspace.AlliesSpawn.CFrame + Vector3.new(0,1,0)
	end
end

for i,v in pairs(participants) do
	for i = 1,#participants/2 do
		table.insert(Axis,v)
		table.remove(participants,i)
		v.Character.Torso.CFrame = game.Workspace.AxisSpawn.CFrame + Vector3.new(0,1,0)
	end
end

1 answer

local numPlayers = 0
for i,v in pairs(game.Players:GetChildren()) do
	numPlayers = numPlayers+1
end
for i,v in pairs(game.Players:GetChildren()) do
	if i < math.floor(numPlayers/2) then
		--Do whatever you want
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.