How do you make a player switch teams through a script?

I’m trying to change all players teams to the “Playing” team through a script. I’ve tried doing research, but the results weren’t satisfactory.
Dev forum thing 2

Thanks :smiley:

Players:GetPlayers
Have you researched this?

Yes, I tried researching. I’m learning to script, so I found it a bit confusing.

local teamsService = game:GetService("Teams")
local playersService = gaame:GetService("Players")

for _,p in ipairs(playersService:GetPlayers()) do
   p.Team = teamsService.Playing
end

I suppose this is something you were looking for.
Go through the teams docs too.

Edit: typo in script :sweat_smile:

2 Likes

Thanks! That worked perfectly. Now I have a much better understanding of how this works.

Simply for the purpose of learning, would you mind explaining what this line is for:

for _,p in ipairs(playersService:GetPlayers()) do

This is basically a “for do” loop, except it uses the players as objects and constraints.

1 Like