Issue with Team Name Changing Script

What is my Issue?

This script I have created using the Team:GetPlayers Refrence is not working as I expected.

What I wish to Achieve?

The script is supposed to change the team’s name to "Team Name - Player Count".
I used string.starts to see what the name starts with then change it accordingly, but I keep getting a ServerScriptService.Script:10: attempt to call a nil value error as shown below.
image

It prints each team and their respective player counts just fine, I just can’t seem to find the solution to this problem.

My code:

while true do
wait(2)
	
local teams = game:GetService("Teams"):GetTeams()
for _, team in pairs(teams) do
    local players = team:GetPlayers()
	
	print("Team " .. team.Name .. " has " .. #players .. " players")
	
	string.starts(team.Name, "Lobby -") if true then
	team.Name = "Lobby -" + #players	 
	end
	
	string.starts(team.Name, "Interview -")if true then
	team.Name = "Interview -" + #players	 
	end
	
	string.starts(team.Name, "Staff -") if true then
	team.Name = "Staff -" + #players	 
	end
		
end
	
wait(.1)	
	
end

string.starts(team.Name, "Staff -") if true then
that’s just kind of… incorrect. If statements are if condition then, you’re basically passing each check. You need to do if string.starts(team.Name, string") then instead of the whole line being just sort of mangled

1 Like