Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This auto team script does not team anyong besides models. Would love some help (Should be easy?)

Asked by 6 years ago
game.Players.PlayerAdded:connect(function(player)
    if player:GetRankInGroup(2533886) == 8 then
        player.TeamColor = game.Teams.Security.TeamColor
    else
    if player:GetRankInGroup(2533886) >= 1 then
    player.TeamColor = game.Teams.Models.TeamColor
    else        
            game.Players.PlayerAdded:connect(function(player)
    if player:GetRankInGroup(2533886) <= 0 then
        player.TeamColor = game.Teams.Spectators.TeamColor
    else
                game.Players.PlayerAdded:connect(function(player)
    if player:GetRankInGroup(2533886) >= 12 then
        player.TeamColor = game.Teams.HighRanks.TeamColor 

    end
        end)

    end
        end)

    end
        end
end)


0
High ranks dont work ANDREW50060 1 — 6y
0
Those ends are uneccesary. You don't have to seperate 'else' and 'if', put it together like 'elseif player:GetRankInGroup(2533886) == 8 then ..' hellmatic 1523 — 6y
0
Will that fix it ANDREW50060 1 — 6y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
6 years ago
Edited 6 years ago

You must format your code correctly so that your code is readable. Otherwise, you'll have no idea what you're writing:

game.Players.PlayerAdded:connect(function(player)
        if player:GetRankInGroup(2533886) == 8 then
                player.TeamColor = game.Teams.Security.TeamColor
        else
                if player:GetRankInGroup(2533886) >= 1 then
                        player.TeamColor = game.Teams.Models.TeamColor
                else
                        game.Players.PlayerAdded:connect(function(player)
                                if player:GetRankInGroup(2533886) <= 0 then
                                        player.TeamColor = game.Teams.Spectators.TeamColor
                                else
                                        game.Players.PlayerAdded:connect(function(player)
                                                if player:GetRankInGroup(2533886) >= 12 then
                                                        player.TeamColor = game.Teams.HighRanks.TeamColor
                                                end
                                        end)
                                end
                        end)
                end
        end
end)

This "pyramid" look is not a good sign. Having :Connections inside :Connections is not a good sign.

Right now, if you just read what your code does, you only start waiting for rank 12s and beyond AFTER

  • a rank not 8 joins
  • then a rank 0 joins
  • then a rank not 0 joins

Use either separate :Connections for each rank, or more simply, an if...elseif chain inside a single :Connect handler

Ad

Answer this question