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

How can I change the Team of all the players in the game ?

Asked by 2 years ago

So, I'm making a game where all players must change teams after sixty seconds. But my method doesn't work, how can I do it?

Actual code : (Script in serverScriptService)

local players = game.Players:GetPlayers()

function launchGame()
    players.TeamColor = BrickColor.new("Burlap")
    players:LoadCharacter()
end

wait(60)
launchGame()

2 answers

Log in to vote
0
Answered by
appxritixn 2235 Moderation Voter Community Moderator
2 years ago

Problem

You are setting the index of the players table "TeamColor" to a new Burlap BrickColor. You are also attempting to call the LoadCharacter method on the table returned by game.Players:GetPlayers().

Solution

Use a for loop to iterate through the table and set the team colors of each player, and load their characters.

Code

local players = game.Players:GetPlayers()

function launchGame()
    for _,player in ipairs(players) do
        player.TeamColor = BrickColor.new("Burlap")
        player:LoadCharacter()
    end
end

wait(60)
launchGame()

Conclusion

If you have any more questions, feel free to reach out to me on Discord (phxntxsmic#2021).

Ad
Log in to vote
0
Answered by
Cirillix 110
2 years ago
Edited 2 years ago
wait(60)
for i,v in pairs(game.Players:GetPlayers()) do --Loop through all players
v.Team = game.Teams.Team --Change ''Team'' for the name of the team
v:LoadCharacter()
end

Answer this question