I have given this advice before:
If you don't use coroutine.yield, you have no business using coroutines at all. Use spawn or delay if you just want to make a new "thread".
Also, tab your code correctly.
It's idiomatic to use while true do instead of repeat until nil. TheCowsComeHome is useless.
Only the Blue team is looked at repeatedly. Red is only looked at once. I'm guessing this is a mistake.
player is only defined once; thus the script will only know about the players that joined when it started running (if this is a normal script in ServerScriptService or the workspace, that means no one).
It also is a list of players, so you should really call it players. Since you only use it in to for i = 1, loops... you should probably just skip to using a generic for loop. I also recommend using :GetPlayers() instead of :GetChildren().
I don't know what this code is supposed to accomplish. I'm guessing you want to make RedGK and BlueGK have the number of players currently on that team. In that case there should be no waits in the loop over the players -- there shouldn't be time passing between handling individual players.
You should also make a function instead of repeating yourself for Blue and Red.
At this point your code would look like this:
workspace.BlueGK.Value = 0
workspace.RedGK.Value = 0
function CountTeam(team)
local count = 0
for _, player in pairs(game.Players:GetPlayers()) do
if player.TeamColor == team then
count = count + 1
end
end
return count
end
while true do
workspace.BlueGK.Value = CountTeam( BrickColor.new("Deep blue") )
workspace.RedGK.Value = CountTeam( BrickColor.new("Bright red") )
wait(0.03)
end
No coroutine, only one function -- and it's a real one, and it's much shorter (and more correct).
A remark:
You don't really need BlueGK or RedGK for anything. It's just as reasonable to juse use CountTeam directly.
3 comments
Could you be more specific?
Make sure you give us your whole script. Also, please tab your script as well so we may easily read and help you. Also, explain the error, what is suppose to happen, and what is happening. Then we can assist you
What is this even supposed to do?