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?
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.
I think this is what you're trying to do
if team.Name == "Hiding" and #players > 0 then game.Workspace.HidingWinTestA.Value = true end