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?

local plr=game.Players.LocalPlayer
local s = Instance.new("ScreenGui")
        s.Name = "AIGui"
        s.Parent = plr:WaitForChild("PlayerGui")
        local f = Instance.new("Frame",s)
        f.Size = UDim2.new(0,400,0,250)
        f.Position = UDim2.new(0,540,0,100)
        f.BackgroundColor3 = Color3.new(255,0,0)
        f.BackgroundTransparency = 0.7
        wait(1)
        local tl = Instance.new("TextLabel",f)
        tl.Position = UDim2.new(0,50,0,165)
        tl.TextSize = 15
        local a = game.Teams.Raiders:GetChildren()
        for i = 1, #a do
        tl.Text = AI..":"..i
        end

2 answers

Log in to vote
0
Answered by 7 years ago
local Team = {game.Teams.Raiders,game.Teams.["EnterOtherTeamNameHere"]}

local x
local y

for _, Player in pairs(game.Players:GetChildren()) do
    if Player.Team == Team[1] then
        x = x + 1
        --Do whatever
    elseif Player.Team == Team[2] then
        y = y + 1
        --Do whatever
    end
end

tl.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.

local numOfPlrs = #game.Players:GetChildren()

tl.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