The script is supposed to remove the team owners team when they leave and move other team members to the rogues team but it only works when there is someone in the team other than the leader, It's only moving the other players to rogues and not removing the team. What am I doing wrong?
function Leaving(Player)
if Player.Team ~= nil and Player.Team.Leader.Value == Player.Name then
local LeaderTeam = Player.Team
for i, v in pairs(Player.Team:GetPlayers()) do
v.Team = game.Teams.Rogues
LeaderTeam:Remove()
end
end
end
game.Players.PlayerRemoving:connect(Leaving)
