Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

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

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
0
Answered by 9 years ago
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
Ad

Answer this question