Greetings, I want a team without members to not show up, but I don't know how to do it. How could I make it?
How can I hide a team without members?
1 answer
You can use a combination of PlayerRemoved and a custom function for when a player is added to solve this. When the game runs, you can record all the teams in a table, and set their parent to nil (removing them from the leaderboard):
local Teams = game:GetService("Teams")
RecordedTeams = {}
for _,Team in pairs(Teams:GetChildren()) do
RecordedTeams[Team.Name] = Team
Team.Parent = nil
end
This will store the team under the name of the team in the RecordedTeams dictionary, and then get rid of the team from the leaderboard (by removing it from the Teams service).
Then, when a new player joins a team, you can put the team back inside of the Teams service, making it appear again:
local function SetTeam(Player,TeamName)
if RecordedTeams[TeamName] then
RecordedTeams[TeamName].Parent = Teams
Player.Team = RecordedTeams[TeamName]
end
end
This will re-insert the team if it isn't already there, while also setting the given player's team to be that team.
Finally, you want to remove the team when the last player in it leaves. This is where the PlayerRemoved function comes in.
for _,Team in pairs(RecordedTeams) do
Team.PlayerRemoved:Connect(function()
if #Team:GetPlayers() <= 0 then --if the player leaving was the last player in the team
Team.Parent = nil
end
end)
end
Hope this helps!
1 comment
Great, thank you.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
destroy the team, when someone would normally join, remake it