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

Adding players to a random team?

Asked by 4 years ago
Edited 4 years ago

I want all players to teleport to 2 random teams. Where should I begin in this script? If so, an example would be helpful for me.

local GameTime = 10
local text = script.Text

while true do
    wait(5)
    text.Value = "Intermission..."
    print("Intermission...")
    wait(1)
    local RandomNumber = math.random(1, 1)
    local Map = game.ServerStorage["Map".. RandomNumber]

    Map:Clone().Parent = workspace.MapFolder

    ftime = GameTime

    local SpawnCount = Map.SpawnCount

    wait(5)

    for _, v in pairs(game.Players:GetChildren())do
        Player = Instance.new("StringValue",workspace.Players)
        Player.Name = v.Name
        randomN = math.random(1, SpawnCount.Value)
        v.Character.Torso.CFrame = CFrame.new(Map["Spawn"..randomN].Position+Vector3.new(0,3,0))
    end

1 answer

Log in to vote
0
Answered by
mc3334 649 Moderation Voter
4 years ago

to split the players into teams, you can do the following:

teams = {TeamInstanceHere,TeamInstanceHere}
local current = 1

for _,v in pairs(game.Players:GetChildren()) do
    v.Team = teams[current]
    if current == #teams then
        current = 1
    else
        current = current+1
    end
end

This will split the players evenly between any team instances in the table "Teams". With further questions/comments/concerns, feel free to reply! Happy sccripting! ~mc3334

0
Thank you! I'll look into the script and let you know if it's working. User#27966 0 — 4y
0
I'm getting an error on line 05. Workspace.Main Script:32: bad argument #3 to 'Team' (Object expected, got string) User#27966 0 — 4y
0
Nevermind, I got it. User#27966 0 — 4y
Ad

Answer this question