Ive tried using :GetPlayers but im not sure how to make it see how many players are on the team or how to make a script that team changes, im making a minigames place so this is very important to know, Thanks!
- Lua and Unity Scripter, Jayferg14
Ive tried using :GetPlayers but im not sure how to make it see how many players are on the team or how to make a script that team changes, im making a minigames place so this is very important to know, Thanks!
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!
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. :)
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.
2 comments
Post your attempt and we can work from there :)
https://devforum.roblox.com/t/player-team-and-team-getplayers/26610