I need it in a script when a certain event happens, it changes the players team. I need the below script to choose random teams.

--------------------------
-- Random map is chosen --
--------------------------  

    if game.Players.NumPlayers > 1 then
        h.Value = "Deciding what map to play"
        wait(3)
        ranMap = math.random(1, #map)
        mapChosen = map[ranMap]
        h.Value = "Map Chosen: " .. mapChosen.Name
        wait(2)
        mapChosenClone = mapChosen:Clone()
        mapChosenClone.Parent = game.Workspace.MapHolder
        wait(2)

------------------------
-- Picks random teams --
------------------------

        players = game.Players:GetChildren()

        teams = {"Bright red","Bright blue"}
        num = 1

        for i,v in pairs(players) do
            v.TeamColor = BrickColor.new(teams[num])
            num = num + 1
            if num > #teams then
                num = 1
            end
        end

11 comments

0

What are you asking? Can you be more clear, this would change the TeamColor of each player.

0

So you want it to work how it is, except the players go on random teams instead of back and forth?

0

I want it so that the players are split into two teams. Red and blue, so I need this script to change a players current team to either red or blue

0

Cuase it itsnt working, it does nothing

0

When do you want to run it? As of now you are just running it right away (when the server is created) so at that time there will be no players.

0

ill add what comes before and after

0

im not posting the whole thing, cause theres 150+ lines to the actual script

0

Are you positive the player(s) are not neutral when you change their teamcolor? You can manually set their neutral property to false but other than that it seems fine. Is there an output?

0

k thanks, that was the problem, thanks LD

0

except now when your character dies they dont repsawn at a spawn

0

Make sure the TeamColor of the spawn matches the team's TeamColor and that the spawn is not neutral