Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Team Players Count?

How do I make this work in a Script, not a LocalScript?

function getPlayersOnTeam(teamColor)
local players = {}; 
for i,v in pairs(game.Players:GetPlayers()) do 
if (v.TeamColor.Name == teamColor) then 
table.insert(players, v); 
end end return players end;

game:GetService("RunService").RenderStepped:connect(function()
hn = #getPlayersOnTeam("Bright blue");
sn = #getPlayersOnTeam("Dark stone grey");
end)

p.s I want to have a count of the players!

1 answer

Try

function GetPlayersOnTeam(Color)
	local Players={}
	for i,v in pairs(game.Players:GetChildren()) do
		if v.ClassName=="Player" then
			if v.TeamColor.Name==Color then
				table.insert(Players,v)
			end
		end
	end
	return Players
end

coroutine.wrap(function()
	while wait() do
		hn=#GetPlayersOnTeam("Bright blue")
		sn=#GetPlayersOnTeam("Dark stone grey")
	end
end)()

2 comments

0

mu6666mu, does this code that you have redone constantly update the count of players on each team? or what does it do exactly?

1

I've edited it to constantly get the number of players

This discussion is preserved as it was. New answers, comments, and votes are closed.