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?

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)

I want this code to work in a Script, not a LocalScript. How would I make it work? [I want the code to work so that it constantly updates the count of players on each team]

1 answer

This is the same code, but just easier to read:

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)

So, it doesn't work?

If it's not working, and you're trying to run it from a server script, I believe that RenderStepped is only able to be used in LocalScripts. Correct me if I'm wrong.

2 comments

0

yes it is. So how do i run it from a server script?

0

Then use .Stepped instead of .RenderStepped.

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