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

Why wont this split teams?? Could someone give me the solution??

Asked by 10 years ago
local msg = Instance.new('Message',workspace)
msg.Text = "Now choosing teams..."
wait(5)
msg:Destroy()
local team1, team2 = 'Red', 'Blue';

repeat
team1, team2 = Game:GetService'Teams':FindFirstChild(team1), Game:GetService'Teams':FindFirstChild(team2)
wait(1/30) until team1 and team2

for i, player in pairs(Game:GetService'Players':GetPlayers'') do
player.TeamColor = i%2==0 and team1.TeamColor or team2.TeamColor
end

The problem is that it wont split the teams, correctly..

1 answer

Log in to vote
0
Answered by
jobro13 980 Moderation Voter
10 years ago

First of all: Nice coding style - good use of the and and or operators.

It should work. However, your repeat-until block has a kind of unlogic meaning: it will only run once in any case, while it is intended to wait for the team1 and team2 variables.

What would be better? Well, just use :WaitForChild. Delete line 7, 8 and 9 and instead put on line 5:

local teams = game:GetService("Teams") -- this is how I write it down but yours is also correct!
local team1, team2 = teams:WaitForChild("Red"), teams:WaitForChild("Blue")

Test that, because it should work.

Ad

Answer this question