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

is there a way to make a team change script and a script to see how many players on a team?

2 answers

This should work for you.

local team = game.Teams.TeamName --team location
local count = 0
for i,players in pairs(game.Players:GetChildren()) do --Before anyone corrects me to use :GetPlayers, its basically the same thing. What else are you going to store in the Players service.
	if players.Team == team then
	count = count + 1
	print("There are "..count.." players on "..team.Name.."!")
end
end

This was written off the top of my head, so i apologize if this does not work for you. Please accept my answer if this helped!

1 comment

0

Use :GetPlayers in a Team object or whatever it is called.

local team = game.Teams.TeamName -- TeamName is the name of the team
local teamAmount = team:GetPlayers() -- :GetPlayers() gets the amount of players

print(#teamAmount) -- the pound sign (#) means NumberOf, so in Lua terms english terms, it gets the amount of objects in the table

--[[ Example:
12 people on the team "TeamName"
the amount of players that would return in the ":GetPlayers" would be 12.
If you need anymore information contact me on discord @Goat#2976
--]]

Or if you didn't want to create a whole variable for it, do this:

local team = game.Teams.TeamName
print(#team:GetPlayers())
-- This basically does the same as above, but without setting a whole variable to ":GetPlayers". Both have their purposes. :)

2 comments

0

I just joined this site and starting answering questions, unsure what I did wrong. I saw the other post but I thought my coding was simpler. Both works :P

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