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

How can I track specific people on teams?

Asked by 4 years ago

I need to track the amount of players per team to determine who wins. I was given this script by another user

local teams = game:GetService("Teams"):GetTeams()
for _, team in pairs(teams) do
    local players = team:GetPlayers()
    print("Team " .. team.Name .. " has " .. #players .. " players")
end

and it worked just fine. However, when I tried to add an if ten statement it came up with this error message: Workspace.HidingWin:6: attempt to call a string value

local teams = game:GetService("Teams"):GetTeams()
for _, team in pairs(teams) do
    local players = team:GetPlayers()
    print("Team " .. team.Name .. " has " .. #players .. " players")
    if team.Name("Hiding").. #players > 0 then
        game.Workspace.HidingWinTestA.Value = true
    end
end

How can I fix this?

2 answers

Log in to vote
0
Answered by 4 years ago

I think it's because you wrote if team.Name("Hiding").. #players > 0 which wouldn't work. Instead, use if team.Name == "Hiding" followed by the keyword, and. It should look like this:

local teams = game:GetService("Teams"):GetTeams()

for _, team in pairs(teams) 
    local players = team:GetPlayers()
    print("Team " .. team.Name .. " has " .. #players .. " players")

    if team.Name == "Hiding" and #players > 0 then
        workspace.HidingWinTestA.Value = true
    end
end

Also, if it still errors, make sure the instance, HidingWinTestA isn't a string value.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I think this is what you're trying to do

if team.Name == "Hiding" and #players > 0 then
    game.Workspace.HidingWinTestA.Value = true
end
0
This should work. KingDomas 153 — 4y

Answer this question