Players.PlayerRemoving:Connect(function(player)
for i, team in pairs(game:GetService("Teams"):GetTeams()) do
if #team:GetPlayers() == 0 then
print("Player left!")
team:Destroy()
end
end
end)
Print
19:17:52.851 ▶ Player left! (x8) - Server - Script:10
It runs but it doesnt destroys the team for some reason
Seems to be working fine for me. Are you changing team on the client-side?
Also, here’s an updated version I made.
local Teams = game:GetService('Teams')
local GetTeams = Teams:GetChildren()
for i = 1, #GetTeams do
local Team = GetTeams[i]
Team.PlayerRemoved:Connect(function(Player)
print(('Player %s has left the team %s.'):format(Player.Name, Team.Name))
if #Team:GetPlayers() == 0 then
Team:Destroy()
print(('Team %s has been destroyed.'):format(Team.Name))
end
end)
end
Try using my script instead, and — I don’t know what GetTeamFromPlayer is.
Also, you shouldn’t use the parent argument with Instance.new if you are modifying its properties afterwards.
GetTeamFromPlayer is my function, it works hahah
still doesnt work might be something wrong. Used your script, might be the game, thank you for the help! I will try to fix it
If my script doesn’t work then there’s definitely something wrong on your side, I cannot help you if that’s the case since everything else seems to be correct.
game.Players.PlayerRemoving:Connect(function(player)
for i,team in pairs(game:GetService("Teams"):GetChildren()) do
if #team:GetPlayers() <= 0 then
print("Last Player left!")
team:Destroy()
end
end
end)
Have fun scripting. and also, if this is not the full script post the full script as well. Loops without Spawn functions will yield scripts.