I am trying to change the team of every player who's in the "Allies" team to the "Enemies" team but I'm not sure what I'm doing wrong here, or I'm still learning so it may actually be a simple mistake but I can't seem to find it. This is the script:
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
function onChatted(msg, recipient, speaker)
local c = game.Players:GetPlayers()
local source = string.lower(msg)
if (msg == "!force change") and player.Name == "Player1" then
for i = 1,#c do
if c[i].Team == "Allies" then
c[i].Team = "Enemies"
end
end
end
end
end)
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end
game.Players.PlayerAdded:connect(onPlayerEntered)

7 comments
The team of all the players on team "Allies" only changes to "Enemies" when "Player1" is the player that joins the server. When exactly do you want the players on "Allies" to switch to "Enemies"?
I want them to change when the message "!force change" is written in chat.
You want everyone in the game to change teams when "!force change" is written in chat?
this should work, but youre attempting some weird stuff with that event
I just want to make sure I know exactly what you want so I can give you an accurate answer.
You also have your code organized kind of awkwardly. I don't see a need for 2 PlayerAdded events.
This is exactly what I want to happen: When the said Player1 uses the "command" !force change, only the players on the Allies team should get moved to the Enemies team.