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

How would I make my counting players on a team work?

Asked by 7 years ago

So far I tried to make the for i loop count, but it wouldn't work. It would instead just show as a label with the text implying "label" how would I overcome this issue?

01local plr=game.Players.LocalPlayer
02local s = Instance.new("ScreenGui")
03        s.Name = "AIGui"
04        s.Parent = plr:WaitForChild("PlayerGui")
05        local f = Instance.new("Frame",s)
06        f.Size = UDim2.new(0,400,0,250)
07        f.Position = UDim2.new(0,540,0,100)
08        f.BackgroundColor3 = Color3.new(255,0,0)
09        f.BackgroundTransparency = 0.7
10        wait(1)
11        local tl = Instance.new("TextLabel",f)
12        tl.Position = UDim2.new(0,50,0,165)
13        tl.TextSize = 15
14        local a = game.Teams.Raiders:GetChildren()
15        for i = 1, #a do
16        tl.Text = AI..":"..i
17        end

2 answers

Log in to vote
0
Answered by 7 years ago
01local Team = {game.Teams.Raiders,game.Teams.["EnterOtherTeamNameHere"]}
02 
03local x
04local y
05 
06for _, Player in pairs(game.Players:GetChildren()) do
07    if Player.Team == Team[1] then
08        x = x + 1
09        --Do whatever
10    elseif Player.Team == Team[2] then
11        y = y + 1
12        --Do whatever
13    end
14end
15 
16tl.Text = AI..":"..x

You will probably need to modify this to be compatible with your script.

Ad
Log in to vote
0
Answered by
Mineloxer 187
7 years ago

If I understand your question correctly, you want to get the number of players.

1local numOfPlrs = #game.Players:GetChildren()
2 
3tl.Text = AI .. ":" .. numOfPlrs

NOTE: This won't change if players leave or join. So you just have to create a function that updates the Text. And hook up event listeners to it.

0
I want to get the number of players on a specific team. Sorry about that. legomaster38 39 — 7y

Answer this question