Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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
0
Post your attempt and we can work from there :) PreciseLogic 271 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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!

0
Use :GetPlayers in a Team object or whatever it is called. hiimgoodpack 2009 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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. :)
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 gmatchOnRoblox 103 — 6y

Answer this question